This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+3 votes

I'm still relatively new to Godots node system and try to understand how to best access certain nodes, but I've run into issues with my lacking understanding of runtime-generated nodes/scenes.

I made two scenes to understand Dialogue boxes, scene 1) and scene 2).

Scene 1) is called scnDia.tscn, which contains a root control node called Dia. Underneath are a bunch of irrelevant nodes, and a label called DebugText.
Scene 2) is called scnTst
calling, Node2D as a root node, and another Node 2D called TextboxPos. 2) also has a button, sole function is to generate 1) on the push of a button during runtime.

func _on_Button_pressed():
var dialoguebox = preload("res://Testscenes/scn_Dia.tscn")
var instance = dialoguebox.instance()

This is working so far, and the debugger prints the children of I think the runtime generated version of Dia:

How can I get the label in the runtime generated scene, and tell it to display a different text?

Godot version 3.4.4.stable
in Engine by (19 points)

1 Answer

0 votes

Once you have a valid reference to an instanced scene, you can access its children using typical mechanisms. For instance, this would get a child named Node2D from the instanced scene...


or, to get a a child of the above Node2D named Tween...


Take a look at this docs page for more details.

by (22,704 points)

Hi! Thanks for your super fast reply. That documentation page is actually where I got the base code from, but I still feel like I still lack understanding something.
They don't particularly mention runtime generated nodes in the sense of being able to access properties of nodes in the hierarchy of said run time generated node.

Maybe it is just not possible, but I suspect I simply don't manage to get the syntax right.
If you happen to have more information I'd highly appreciate it!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.