-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document the exact order of all lifetime signals/callbacks/notifications #5492
Comments
Related to #3475 (possible duplicate)? Either way, this issue has more information, so I'd vouch for keeping it open. |
What would be a good section of the documentation to put this in? |
@skyace65: Scripting, core features, new subpage (like "Groups" is one, or "Nodes and scene instancing" is another). |
From the list children exited first as well as exiting and then their parent, or am I missing something, it's late over here so I might be dumb. |
Ah you seem to be right. The order is still different though. |
Yeah, it seems _exit_tree(), tree_exiting, notification_exit_tree are "deep bottom up", tree_exited is "deep top to bottom", notification_predelete is "deep bottom up". tree_exited has the same order as _ready() callback, notification_ready and ready and notification_post_enter_tree. Well I guess I'd expect all the exit and predelete to follow the same order, it's interesting to see it's not, I have no idea what reason could be behind it. :) |
I did look up into this a while back (I just found this issue), I'll link it here in case it is useful:
|
Executing the same script on 4.2.1 now yields different results.
Concerning the inconsistency? between Given the behavior seems to have changed over time, I'm not sure how much should be left out as "implementation details" when creating the documentation.
|
Here's the test scene with up-to-date script: |
Neat. One of the first things I did when getting to know the engine was make a test protect something like this one. Mine, and my takeaways, are here: https://github.com/allenwp/godot-script-execution-order |
Your Godot version:
3.4.1
Issue description:
From time to time, I keep seeing people confused about order of lifetime methods. Recently there was a bug report, where it turned out that the user tried to access an
onready
variable inside a callback from signal emitted in_ready()
of a child node. It's convoluted, but theonready
variable wasn't initialized in parent, because child nodes will call their_ready()
first.We do have some docs about order of some methods, but there isn't any comprehensive guide that lists all callbacks/notifications etc and order of variable initialization.
I made a small test project. For a single node the order is this:
_init()
callbackNOTIFICATION_ENTER_TREE
_enter_tree()
callbacktree_entered
signalNOTIFICATION_POST_ENTER_TREE
_ready()
callbackNOTIFICATION_READY
ready
signalIt gets super-complicated when node has children. My test scene was like this:
Tested with this script, that prints about everything for when node is created and destroyed:
And the result:
Interesting/not expected stuff:
_init()
is called for every node in scene before any other method and before any is added to treeenter_tree
is called in the same order as init, i.e. depth-firstNOTIFICATION_POST_ENTER_TREE
happens right before_ready()
callback in any node, butonready
variables aren't initialized yet_ready()
is the earliest place where you can useonready
variables and initialization ofonready
variables has the same order as_ready()
callbacktree_exiting
is emitted first in children, same asNOTIFICATION_PREDELETE
, buttree_exited
is the opposite; parents emit it first.tree_exiting
is "equivalent" ofready
andtree_exited
is "equivalent" ofenter_tree
, but they are reversed, i.e. when destroying nodes it's as if "ready" came first instead of lastThat's lots of information, not sure how much of it is really useful, but it would be nice to have it documented somewhere. Knowing the exact order of things in tree might come in handy for some complicated scene logic and might save some confusion when things don't get called in the order you'd expect.
The text was updated successfully, but these errors were encountered: