Determining when all nodes in the scene tree are ready. Godot 4 c#

Is there a recommended way of determining if all nodes in the scene tree are ready?
Thank you.

Add a script to your scene root node (Godot 3.x example):

 func _ready():
 	get_viewport().connect("ready", self, "_on_scenetree_ready")
 
 
 func _on_scenetree_ready():
 	print("everything is ready")

Assuming you don’t have other viewports in this scene, this hooks into the scenetree’s default viewport’s ‘ready’ signal, which fires last of all after your scene nodes have initialised/readied.

It depends entirely on what you mean by “ready”, if you mean just "have they all called _ready then just getting it from the root node of your scene should be sufficient, but it depends on what you mean by “ready”, some nodes aren’t fully ready until after a frame or two as they initialize things and communicate with the engine servers etc., like navigation and physics

1 Like

Since you are in control of the scene I’d suggest just using the _ready method of your scene root to handle this, if what you’re looking for is all of them having fired their _ready, as it fires “bottom up”, or you can use:

get_tree().current_scene.connect(&"ready", _on_scenetree_ready)

(Note that for 4.x you have to use this syntax, not self, "_on_scenetree_ready")
Or just:

get_tree().current_scene.ready.connect(_on_scenetree_ready)

C# syntax is specific of course, see the documentation

There is also the ready signal on node classes

This would allow for an external observer to know when a scene is ready.

That’s exactly what two other people have already suggested…

A third time is the charm :stuck_out_tongue_winking_eye:

1 Like

Thanks to everyone for your replies. It has been very helpful.

1 Like