MainLoop is the abstract base class for a Godot project's game loop. It is inherited by SceneTree, which is the default game loop implementation used in Godot projects, though it is also possible to write and use one's own MainLoop subclass instead of the scene tree.
Upon the application start, a MainLoop implementation must be provided to the OS; otherwise, the application will exit. This happens automatically (and a SceneTree is created) unless a MainLoop Script is provided from the command line (with e.g. godot -s my_loop.gd
) or the "Main Loop Type" project setting is overwritten.
Here is an example script implementing a simple MainLoop:
Emitted when a user responds to a permission request.
Called before the program exits.
Called once during initialization.
Called each physics frame with the time since the last physics frame as argument (delta
, in seconds). Equivalent to Node._physics_process.
If implemented, the method must return a boolean value. true
ends the main loop, while false
lets it proceed to the next frame.
Called each process (idle) frame with the time since the last process frame as argument (in seconds). Equivalent to Node._process.
If implemented, the method must return a boolean value. true
ends the main loop, while false
lets it proceed to the next frame.