Add _after_ready() to ensure that logic runs when all nodes in scenetree are ready #10889
azur-wolve
started this conversation in
Engine Core
Replies: 1 comment 2 replies
-
If you need to wait for a parent to be ready, you can do await get_parent().ready Or if you need to wait for the whole tree to be ready: await get_tree().root.ready I think this is a nice idea but it's really easy to work around it |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Godot aims for intuitiveness and usability.
One of the problems that newcomers always face is the initialization order of nodes regarding READY.
It has been said to be found counter-intuitive multiple times.
(as for the rest of the tree creation, the steps go from up hierarchy to down. Is the ready step that only goes from down to up)
The children come first as its expected that nodes higher in the tree hierarchy use nodes that are lower and not vice-versa, which is a good practice.
However there are cases where is needed to check something on an ancestor from a descendant.
Currently
_ready()
is the last "step" before the first game loop iterationif there were an
_after_ready()
could solve some of that, so its ensured that all nodes have been initialized and are ready with_init()
and_ready()
respectively.Also its handy as we move nodes around the hierarchy when trying new things on scene prototyping stages, so we don't have to worry where they are moved to, and change the code every time, or being limited to avoid changing it.
All that regarding to the initialization step when launching a scene.
Right now to have such behavior would need something like:
Maybe that could throw some problem even?
Beta Was this translation helpful? Give feedback.
All reactions