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
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
Thanks to everyone for your replies. It has been very helpful.