godotengine / godotengine/godot-docs
Processing diagram (game loop)
- Dominant language
- reStructuredText
- Stars
- 5.7k
- Forks
- 3.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 25
Description
I've made a basic main loop diagram by looking at the code. I'd be willing to improve it and adding it to the documentation, but I don't know where or how. For now, I'd like to make sure it's correct and complete.
I needed to know the order things happen inside the Godot engine to better write code for it. I don't think there's something similar in the documentation. There are some pages that give some information but not the whole picture:
- https://docs.godotengine.org/en/stable/tutorials/scripting/scene_tree.html
- https://docs.godotengine.org/en/stable/tutorials/best_practices/godot_notifications.html
- https://docs.godotengine.org/en/stable/tutorials/scripting/idle_and_physics_processing.html
- https://docs.godotengine.org/en/stable/tutorials/inputs/inputevent.html
Please, add any I may have missed, also corrections and suggestions.
Related issues: #9204 #5492
---
# Processing diagram for Godot 4
MainLoop is the scene tree object. In the default configuration it's an `SceneTree` object.
It may lack some platform specific information.
- Call `MainLoop._initialize()`.
- Call `DisplayServer::process_events()`. Processes window manager events
including input.
- Process joystick/gamepad events.
- Physics processing step (run as many times as needed).
- Flush input buffered events when `agile_event_flushing` is true (Android only).
- Call NOTIFICATION_TRANSFORM_CHANGED on nodes and update physics objects transforms.
- Call `MainLoop._physics_process()`.
- Send signal `SceneTree.physics_frame`.
- Process object picking.
- Call `_physics_process()` in the scene nodes.
- Flush unique calls to groups.
- Process timers in physics processing mode.
- Process tweens in physics processing mode.
- Call NOTIFICATION_TRANSFORM_CHANGED on nodes and update physics objects transforms.
- Process `queue_delete()/queue_free()` calls.
- Process deferred calls.
- Physics server step.
- Flush input buffered events when `agile_event_flushing` is true (Android only).
- Idle processing step.
- Call `MainLoop._process()`.
- Automatic polling of MultiplayerAPI.
- Call NOTIFICATION_TRANSFORM_CHANGED on nodes and update physics objects transforms.
- Call `_process()` in the scene nodes.
- Flush unique calls to groups.
- Call NOTIFICATION_TRANSFORM_CHANGED on nodes and update physics objects transforms.
- Process `queue_delete()/queue_free()` calls.
- Change scene if requested. If changed, emit `scene_changed` signal (Godot 4.5+).
- Process timers in idle processing mode.
- Process tweens in idle processing mode.
- Call NOTIFICATION_TRANSFORM_CHANGED on nodes and update physics objects transforms.
- Process deferred calls.
- Rendering. Emits signals `RenderingServer.frame_pre_draw` and `RenderingServer.frame_post_draw`.
- Audio update.
- Debugger iteration.
- Flush input buffered events when `agile_event_flushing` is false (Android only).
- Add frame to MovieWriter if used.
- Optional frame delay to achieve target fps.
- Call `MainLoop._finalize()`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.