Based on my own observations using Godot, not based on the source code, but I wrote a brief overview of how Godot typically operates and the order things are called in:
1: Godot engine initialization and scene loading
2: The root node of the scene has _ready
called
2.1: Then all of the children nodes of the root have _ready
called from top to bottom, depth first style, one node at a time. For example, say you have the following node tree:
- Scene_Root
- * Level
- Key
- Door
- * Player
- * Enemy
In this example, the _ready
function will be called in the following order: Scene_Root -> Level -> Key -> Door -> Player -> Enemy
If you instance a node in _ready
, I believe it will be called after all of the other children. For example, if in Level you spawn a scene called Button, it will be called after _ready
is called in Door.
Edit: See comment by @SIsilicon28 below! The order described above is backwards/opposite of how it works in Godot.
3: Start of game loop. The steps 4-6 will be called until the game is told to quit.
4: Input is queued and placed into _input
and the Input singleton is updated.
5: _process
is called every frame for every object. It is called in the same order as _ready
.
5.1: I do not remember if signals are called after _physics_process
or as soon as they are called. I think when you emit a signal, the function attached to that signal is called instantly, but I might be wrong.
Edit:
5.2: The order _process
is called in can be changed by calling set_process_priority
6: _physics_process
is called every physics frame, which is set to 30
FPS by default (the game renders at 60
FPS by default). The order is the same as detailed in _ready
.
6.1: I could be wrong on this, but I believe the physics actually updates after _physics_process
is called. This is so you can set physics properties on the nodes and then have them update.
7: any queue_free
calls, or anything else queued, is called at this point. Any nodes deleted using queue_free
are freed from memory and the cycle begins anew, starting at step 4. This process continues until the game receives an exit/shut-down event.
7.1: Scenes changed also happen in this step. In this case, all of the nodes are notified of the change in the same order as in _ready
, and are deleted (if necessary) in the same order.
8: When the game is shut down, all nodes have their cleanup function called. It can be accessed using _notification
, and it is called in the same order as _ready
.
8.1: It should be noted that _notification
gets called several times, based on what has happened to the node and the type of notification passed. I have not used _notification
very much myself, so I'm not 100% sure where it fits into the process.
9: Godot frees engine resources and shuts down.
I wrote all of this from memory and I have not looked into the source code to confirm this order, so please take it with a grain of salt. That said, hopefully this helps explain the order that Godot uses.
(Also: Welcome to the forums!)