Why does the function test output appear before the text in the level.gd? I would have thought that because the player.gd script is on the ParentPlayer node which is a child of level1 that the output of the script lelel.gd would appear first then the player.gd script
here is what i’ve found out from Godot’s discord
JL: Ready bubbles up from children to the parent. IIRC, _enter_tree is called from parent to children when the nodes enter the scene, and afterwards, _ready is called in reverse all the way back to the parent. That way, _ready is only called when the children are in the tree.
If code in the child’s _ready depends on your parent being ready first, you can await for the parent to be ready like await get_parent().ready
I then found it in the godot online docunemntation
When instantiating a scene connected to the first executed scene, Godot will instantiate nodes down the tree (making
_init()
calls) and build the tree going downwards from the root. This causes_enter_tree()
calls to cascade down the tree. Once the tree is complete, leaf nodes call_ready
. A node will call this method once all child nodes have finished calling theirs. This then causes a reverse cascade going up back to the tree’s root.
and
Awaiting for signals or coroutines[¶]
The
await
keyword can be used to create coroutines which wait until a signal is emitted before continuing execution. Using theawait
keyword with a signal or a call to a function that is also a coroutine will immediately return the control to the caller. When the signal is emitted (or the called coroutine finishes), it will resume execution from the point on where it stopped.
so the _enter_tree() reads down through tree and _ready get read children to parent
all this because my text on the child said print(" Sorry. I mean BlueSteelAU!") which was being displayed first then print(“Hello World!”).
lol
I hope i haven’t confused people like i’m feeling right now… at least i got it to print the lines to the console in the right order
lol
Thanks for investigating and the follow-up on yourself. I got confused right away as well when I saw the print messages reversed.
tyvm I’m glad that I wasn’t the only one
Great work guys and thanks for posting your solution so that others can benefit from it
Nice one for digging into the order of execution there and sharing your findings,awesome stuff
This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.