Inheritance #
- AudioServer
- CameraServer
- ClassDB
- DisplayServer
- EditorFileSystemDirectory
- EditorInterface
- EditorPaths
- EditorSelection
- EditorUndoRedoManager
- EditorVCSInterface
- Engine
- EngineDebugger
- FramebufferCacheRD
- GDExtensionManager
- Geometry2D
- Geometry3D
- IP
- Input
- InputMap
- JNISingleton
- JSONRPC
- JavaClassWrapper
- JavaScriptBridge
- MainLoop (1)
- Marshalls
- MovieWriter
- NativeMenu
- NavigationMeshGenerator
- NavigationServer2D
- NavigationServer3D
- Node (21)
- OS
- OpenXRExtensionWrapperExtension
- OpenXRInteractionProfileMetadata
- Performance
- PhysicsDirectBodyState2D (1)
- PhysicsDirectBodyState3D (1)
- PhysicsDirectSpaceState2D (1)
- PhysicsDirectSpaceState3D (1)
- PhysicsServer2D (1)
- PhysicsServer2DManager
- PhysicsServer3D (1)
- PhysicsServer3DManager
- PhysicsServer3DRendering
ServerHandler
- ProjectSettings
- RefCounted (121)
- RenderData (2)
- RenderSceneData (2)
- RenderingDevice
- RenderingServer
- ResourceLoader
- ResourceSaver
- ResourceUID
- ScriptLanguage (1)
- ShaderIncludeDB
- TextServerManager
- ThemeDB
- TileData
- Time
- TranslationServer
- TreeItem
- UndoRedo
- UniformSetCacheRD
- WorkerThreadPool
- XRServer
- XRVRS
Table of contents
-
virtual func _finalize() -> void -
virtual func _initialize() -> void -
virtual func _physics_process(delta: float) -> bool -
virtual func _process(delta: float) -> bool -
const NOTIFICATION_OS_MEMORY_WARNING = 2009 -
const NOTIFICATION_TRANSLATION_CHANGED = 2010 -
const NOTIFICATION_WM_ABOUT = 2011 -
const NOTIFICATION_CRASH = 2012 -
const NOTIFICATION_OS_IME_UPDATE = 2013 -
const NOTIFICATION_APPLICATION_RESUMED = 2014 -
const NOTIFICATION_APPLICATION_PAUSED = 2015 -
const NOTIFICATION_APPLICATION_FOCUS_IN = 2016 -
const NOTIFICATION_APPLICATION_FOCUS_OUT = 2017 -
const NOTIFICATION_TEXT_SERVER_CHANGED = 2018 -
signal on_request_permissions_result(granted: bool)
MainLoop #
is_instantiable, core, not_builtin_classes
Abstract base class for the game's main loop.
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 ProjectSettings.application/run/main_loop_type project setting is overwritten.
Here is an example script implementing a simple MainLoop:
GDScript
class_name CustomMainLoop
extends MainLoop
var time_elapsed = 0
func _initialize():
print("Initialized:")
print(" Starting time: %s" % str(time_elapsed))
func _process(delta):
time_elapsed += delta
# Return true to end the main loop.
return Input.get_mouse_button_mask() != 0 || Input.is_key_pressed(KEY_ESCAPE)
func _finalize():
print("Finalized:")
print(" End time: %s" % str(time_elapsed))C#
using Godot;
[GlobalClass]
public partial class CustomMainLoop : MainLoop
{
private double _timeElapsed = 0;
public override void _Initialize()
{
GD.Print("Initialized:");
GD.Print($" Starting Time: {_timeElapsed}");
}
public override bool _Process(double delta)
{
_timeElapsed += delta;
// Return true to end the main loop.
return Input.GetMouseButtonMask() != 0 || Input.IsKeyPressed(Key.Escape);
}
private void _Finalize()
{
GD.Print("Finalized:");
GD.Print($" End Time: {_timeElapsed}");
}
} Members #
Methods #
virtual func _finalize() -> void#
Called before the program exits.
virtual func _initialize() -> void#
Called once during initialization.
virtual func _physics_process(delta: float) -> bool#
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.
Note: delta will be larger than expected if running at a framerate lower than Engine.physics_ticks_per_second / Engine.max_physics_steps_per_frame FPS. This is done to avoid "spiral of death" scenarios where performance would plummet due to an ever-increasing number of physics steps per frame. This behavior affects both _process and _physics_process. As a result, avoid using delta for time measurements in real-world seconds. Use the Time singleton's methods for this purpose instead, such as Time.get_ticks_usec.
virtual func _process(delta: float) -> bool#
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.
Note: delta will be larger than expected if running at a framerate lower than Engine.physics_ticks_per_second / Engine.max_physics_steps_per_frame FPS. This is done to avoid "spiral of death" scenarios where performance would plummet due to an ever-increasing number of physics steps per frame. This behavior affects both _process and _physics_process. As a result, avoid using delta for time measurements in real-world seconds. Use the Time singleton's methods for this purpose instead, such as Time.get_ticks_usec.
Annotations #
Constants #
const NOTIFICATION_OS_MEMORY_WARNING = 2009#
Notification received from the OS when the application is exceeding its allocated memory.
Specific to the iOS platform.
const NOTIFICATION_TRANSLATION_CHANGED = 2010#
Notification received when translations may have changed. Can be triggered by the user changing the locale. Can be used to respond to language changes, for example to change the UI strings on the fly. Useful when working with the built-in translation support, like Object.tr.
const NOTIFICATION_WM_ABOUT = 2011#
Notification received from the OS when a request for "About" information is sent.
Specific to the macOS platform.
const NOTIFICATION_CRASH = 2012#
Notification received from Godot's crash handler when the engine is about to crash.
Implemented on desktop platforms if the crash handler is enabled.
const NOTIFICATION_OS_IME_UPDATE = 2013#
Notification received from the OS when an update of the Input Method Engine occurs (e.g. change of IME cursor position or composition string).
Specific to the macOS platform.
const NOTIFICATION_APPLICATION_RESUMED = 2014#
Notification received from the OS when the application is resumed.
Specific to the Android and iOS platforms.
const NOTIFICATION_APPLICATION_PAUSED = 2015#
Notification received from the OS when the application is paused.
Specific to the Android and iOS platforms.
Note: On iOS, you only have approximately 5 seconds to finish a task started by this signal. If you go over this allotment, iOS will kill the app instead of pausing it.
const NOTIFICATION_APPLICATION_FOCUS_IN = 2016#
Notification received from the OS when the application is focused, i.e. when changing the focus from the OS desktop or a thirdparty application to any open window of the Godot instance.
Implemented on desktop and mobile platforms.
const NOTIFICATION_APPLICATION_FOCUS_OUT = 2017#
Notification received from the OS when the application is defocused, i.e. when changing the focus from any open window of the Godot instance to the OS desktop or a thirdparty application.
Implemented on desktop and mobile platforms.
const NOTIFICATION_TEXT_SERVER_CHANGED = 2018#
Notification received when text server is changed.
Constructors #
Enums #
Notifications#
GDScript
enum {
NOTIFICATION_OS_MEMORY_WARNING = 2009,
NOTIFICATION_TRANSLATION_CHANGED = 2010,
NOTIFICATION_WM_ABOUT = 2011,
NOTIFICATION_CRASH = 2012,
NOTIFICATION_OS_IME_UPDATE = 2013,
NOTIFICATION_APPLICATION_RESUMED = 2014,
NOTIFICATION_APPLICATION_PAUSED = 2015,
NOTIFICATION_APPLICATION_FOCUS_IN = 2016,
NOTIFICATION_APPLICATION_FOCUS_OUT = 2017,
NOTIFICATION_TEXT_SERVER_CHANGED = 2018,
}C++ src
enum {
//make sure these are replicated in Node
NOTIFICATION_OS_MEMORY_WARNING = 2009,
NOTIFICATION_TRANSLATION_CHANGED = 2010,
NOTIFICATION_WM_ABOUT = 2011,
NOTIFICATION_CRASH = 2012,
NOTIFICATION_OS_IME_UPDATE = 2013,
NOTIFICATION_APPLICATION_RESUMED = 2014,
NOTIFICATION_APPLICATION_PAUSED = 2015,
NOTIFICATION_APPLICATION_FOCUS_IN = 2016,
NOTIFICATION_APPLICATION_FOCUS_OUT = 2017,
NOTIFICATION_TEXT_SERVER_CHANGED = 2018,
};Operators #
Signals #
signal on_request_permissions_result(granted: bool)#
Emitted when a user responds to a permission request.