0 votes

Let's say that I have a node structure like this, where A is the parent of B and 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?

asked May 10, 2019 in Engine by Aaron Franke (62 points)

1 Answer

0 votes

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.



  #children done, now run parent stuff
answered May 10, 2019 by 2D||!2D (379 points)

That's really impractical and doesn't follow the node-based design. Parents shouldn't have to worry about their children.

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.

@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?

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.