public class MainLoop : Object
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 main Script is provided from the command line (with e.g.
godot -s my_loop.gd, which should then be a MainLoop implementation.
Here is an example script implementing a simple MainLoop:
var time_elapsed = 0
var keys_typed = 
var quit = false
print(“ Starting time: %s” % str(time_elapsed))
time_elapsed += delta
Return true to end the main loop.
if event is InputEventKey and event.pressed and !event.echo:
Quit on Escape press.
if event.scancode == KEY_ESCAPE:
quit = true
Quit on any mouse click.
if event is InputEventMouseButton:
quit = true
print(“ End time: %s” % str(time_elapsed))
print(“ Keys typed: %s” % var2str(keys_typed))
public const Int32 NotificationAppPaused = 1015
public const Int32 NotificationAppResumed = 1014
public const Int32 NotificationCrash = 1012
public const Int32 NotificationOsImeUpdate = 1013
public const Int32 NotificationOsMemoryWarning = 1009
public const Int32 NotificationTranslationChanged = 1010
public const Int32 NotificationWmAbout = 1011
public const Int32 NotificationWmFocusIn = 1004
public const Int32 NotificationWmFocusOut = 1005
public const Int32 NotificationWmGoBackRequest = 1007
public const Int32 NotificationWmMouseEnter = 1002
public const Int32 NotificationWmMouseExit = 1003
public const Int32 NotificationWmQuitRequest = 1006
public const Int32 NotificationWmUnfocusRequest = 1008
public virtual void _DropFiles(string files, int fromScreen)
public virtual void _Finalize()
public virtual void _GlobalMenuAction(object id, object meta)
public virtual bool _Idle(float delta)
Called each idle frame with the time since the last idle frame as argument (in seconds). Equivalent to Node._Process(float).
public virtual void _Initialize()
public virtual void _InputEvent(InputEvent @event)
Called whenever an InputEvent is received by the main loop.
public virtual void _InputText(string text)
Deprecated callback, does not do anything. Use _InputEvent(Godot.InputEvent) to parse text input. Will be removed in Godot 4.0.
public virtual bool _Iteration(float delta)
Called each physics frame with the time since the last physics frame as argument (in seconds). Equivalent to Node._PhysicsProcess(float).
public void Finish()
Should not be called manually, override _Finalize() instead. Will be removed in Godot 4.0.
public bool Idle(float delta)
Should not be called manually, override _Idle(float) instead. Will be removed in Godot 4.0.
public void Init()
Should not be called manually, override _Initialize() instead. Will be removed in Godot 4.0.
public void InputEvent(InputEvent @event)
Should not be called manually, override _InputEvent(Godot.InputEvent) instead. Will be removed in Godot 4.0.
public void InputText(string text)
Should not be called manually, override _InputText(string) instead. Will be removed in Godot 4.0.
public bool Iteration(float delta)
Should not be called manually, override _Iteration(float) instead. Will be removed in Godot 4.0.