How to access child nodes of a runtime generated scene?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Fyodot

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 scn_Dia.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?

:bust_in_silhouette: Reply From: jgodfrey

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.

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!

Fyodot | 2022-06-05 14:17