Topic was automatically imported from the old Question2Answer platform.
Asked By
Aaron Franke
Let’s say that I have a node structure like this, where A is the parent of B and C:
A
B
C
Each has scripts attached, which use _process for logic. Currently, it executes A, then B, then C. However, I need the parent node’s code to execute after the child nodes. How can I force the script attached to A to run after everything else?
Don’t use _process in the child nodes and only call it in the parent. In the parent _process function, call another function in the child nodes passing the delta as an argument. Finally, after you have called the children nodes, continue in the parent _process function.
Parent:
_process(delta):
a.some_function(delta)
b.some_function(delta)
#children done, now run parent stuff
That’s really impractical and doesn’t follow the node-based design. Parents shouldn’t have to worry about their children.
Aaron Franke | 2019-05-10 04:02
On the contrary, in Godot parents do have to worry about their children. It’s children that shouldn’t have to know anything about their parent. Best practice in Godot is for any given branch of the scene tree to be able to run independently, not any given node. Indeed, many built in nodes have specific requirements for children.
Ruckus T-Boom | 2019-05-10 15:25
@Aaron Franke AFAIK you can’t change the calling order of the built in functions. What are you needing to accomplish? Perhaps, there is another way?
2D||!2D | 2019-05-10 19:58
I think what I will end up doing is adding another node as a child, and using that child to call the parent’s scripts. That way, it will be executed last.
I suppose not. That’d be more complex. I’m thinking of either using multiple nodes or manually calling the functions of a “virtual” node in the order you need.
swift502 | 2021-02-11 21:41
This is completely wrong. Scripts are executed in a specific order and they are not multithreaded. If they were, it would be incredibly easy to shoot yourself in the foot.