Engine

package
v0.0.0-...-357ca8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

The Engine singleton allows you to query and modify the project's run-time parameters, such as frames per second, time scale, and others. It also stores information about the current build of Godot, such as the current version.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Advanced

func Advanced() class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

func CaptureScriptBacktraces

func CaptureScriptBacktraces(include_variables bool) []ScriptBacktrace.Instance

Captures and returns backtraces from all registered script languages.

By default, the returned ScriptBacktrace will only contain stack frames in editor builds and debug builds. To enable them for release builds as well, you need to enable ProjectSettings "debug/settings/gdscript/always_track_call_stacks".

If 'include_variables' is true, the backtrace will also include the names and values of any global variables (e.g. autoload singletons) at the point of the capture, as well as local variables and class member variables at each stack frame. This will however will only be respected when running the game with a debugger attached, like when running the game from the editor. To enable it for export builds as well, you need to enable ProjectSettings "debug/settings/gdscript/always_track_local_variables".

Warning: When 'include_variables' is true, any captured variables can potentially (e.g. with GDScript backtraces) be their actual values, including any object references. This means that storing such a ScriptBacktrace will prevent those objects from being deallocated, so it's generally recommended not to do so.

func GetArchitectureName

func GetArchitectureName() string

Returns the name of the CPU architecture the Godot binary was built for. Possible return values include "x86_64", "x86_32", "arm64", "arm32", "rv64", "ppc64", "loongarch64", "wasm64", and "wasm32".

To detect whether the current build is 64-bit, or the type of architecture, don't use the architecture name. Instead, use OS.HasFeature to check for the "64" feature tag, or tags such as "x86" or "arm". See the Feature Tags documentation for more details.

Note: This method does not return the name of the system's CPU architecture (like OS.GetProcessorName). For example, when running an x86_32 Godot binary on an x86_64 system, the returned value will still be "x86_32".

func GetFramesDrawn

func GetFramesDrawn() int

Returns the total number of frames drawn since the engine started.

Note: On headless platforms, or if rendering is disabled with --disable-render-loop via command line, this method always returns 0. See also GetProcessFrames.

func GetFramesPerSecond

func GetFramesPerSecond() Float.X

Returns the average frames rendered every second (FPS), also known as the framerate.

func GetLicenseInfo

func GetLicenseInfo() map[string]string

Returns a data structure of licenses used by Godot and included third party components. Each entry is a license name (such as "Expat") and its associated text.

func GetLicenseText

func GetLicenseText() string

Returns the full Godot license text.

func GetMainLoop

func GetMainLoop() MainLoop.Instance

Returns the instance of the MainLoop. This is usually the main SceneTree and is the same as Node.GetTree.

Note: The type instantiated as the main loop can changed with ProjectSettings "application/run/main_loop_type".

func GetPhysicsFrames

func GetPhysicsFrames() int

Returns the total number of frames passed since the engine started. This number is increased every physics frame. See also GetProcessFrames.

This method can be used to run expensive logic less often without relying on a Timer:

if Engine.GetPhysicsFrames()%2 == 0 {
	// Run expensive logic only once every 2 physics frames here.
}

func GetPhysicsInterpolationFraction

func GetPhysicsInterpolationFraction() Float.X

Returns the fraction through the current physics tick we are at the time of rendering the frame. This can be used to implement fixed timestep interpolation.

func GetProcessFrames

func GetProcessFrames() int

Returns the total number of frames passed since the engine started. This number is increased every process frame, regardless of whether the render loop is enabled. See also GetFramesDrawn and GetPhysicsFrames.

This method can be used to run expensive logic less often without relying on a Timer:

if Engine.GetProcessFrames()%5 == 0 {
	// Run expensive logic only once every 5 process (render) frames here.
}

func GetScriptLanguage

func GetScriptLanguage(index int) ScriptLanguage.Instance

Returns an instance of a ScriptLanguage with the given 'index'.

func GetScriptLanguageCount

func GetScriptLanguageCount() int

Returns the number of available script languages. Use with GetScriptLanguage.

func GetSingleton

func GetSingleton(name string) Object.Instance

Returns the global singleton with the given 'name', or null if it does not exist. Often used for plugins. See also HasSingleton and GetSingletonList.

Note: Global singletons are not the same as autoloaded nodes, which are configurable in the project settings.

func GetSingletonList

func GetSingletonList() []string

Returns a list of names of all available global singletons. See also GetSingleton.

func GetWriteMoviePath

func GetWriteMoviePath() string

Returns the path to the MovieWriter's output file, or an empty string if the engine wasn't started in Movie Maker mode. The default path can be changed in ProjectSettings "editor/movie_writer/movie_file".

func HasSingleton

func HasSingleton(name string) bool

Returns true if a singleton with the given 'name' exists in the global scope. See also GetSingleton.

fmt.Println(Engine.HasSingleton("OS"))          // Prints true
fmt.Println(Engine.HasSingleton("Engine"))      // Prints true
fmt.Println(Engine.HasSingleton("AudioServer")) // Prints true
fmt.Println(Engine.HasSingleton("Unknown"))     // Prints false

Note: Global singletons are not the same as autoloaded nodes, which are configurable in the project settings.

func IsEditorHint

func IsEditorHint() bool

Returns true if the script is currently running inside the editor, otherwise returns false. This is useful for @tool scripts to conditionally draw editor helpers, or prevent accidentally running "game" code that would affect the scene state while in the editor:

if Engine.IsEditorHint() {
	DrawGizmos()
} else {
	SimulatePhysics()
}

See Running code in the editor in the documentation for more information.

Note: To detect whether the script is running on an editor build (such as when pressing F5), use OS.HasFeature with the "editor" argument instead. OS.has_feature("editor") evaluate to true both when the script is running in the editor and when running the project from the editor, but returns false when run from an exported project.

func IsEmbeddedInEditor

func IsEmbeddedInEditor() bool

Returns true if the engine is running embedded in the editor. This is useful to prevent attempting to update window mode or window flags that are not supported when running the project embedded in the editor.

func IsInPhysicsFrame

func IsInPhysicsFrame() bool

Returns true if the engine is inside the fixed physics process step of the main loop.

package main

import (
	"fmt"

	"graphics.gd/classdb/Engine"
	"graphics.gd/classdb/Node"
)

type ExampleInPhysicsFrame struct {
	Node.Extension[ExampleInPhysicsFrame]
}

func (e *ExampleInPhysicsFrame) EnterTree() {
	// Depending on when the node is added to the tree,
	// prints either "true" or "false".
	fmt.Println(Engine.IsInPhysicsFrame())
}

func (e *ExampleInPhysicsFrame) Process(delta float64) {
	fmt.Println(Engine.IsInPhysicsFrame()) // Prints false
}

func (e *ExampleInPhysicsFrame) PhysicsProcess(delta float64) {
	fmt.Println(Engine.IsInPhysicsFrame()) // Prints true
}

func Log

func Log(v ...any)

Log prints one or more arguments to strings in the best way possible to standard error line

func Logv

func Logv(v ...any)

Logv prints if verbose mode is enabled (OS.is_stdout_verbose returning true), converts one or more arguments of any type to string in the best way possible and prints them to the console.

func MaxFps

func MaxFps() int

The maximum number of frames that can be rendered every second (FPS). A value of 0 means the framerate is uncapped.

Limiting the FPS can be useful to reduce the host machine's power consumption, which reduces heat, noise emissions, and improves battery life.

If ProjectSettings "display/window/vsync/vsync_mode" is Enabled or Adaptive, the setting takes precedence and the max FPS number cannot exceed the monitor's refresh rate.

If ProjectSettings "display/window/vsync/vsync_mode" is Enabled, on monitors with variable refresh rate enabled (G-Sync/FreeSync), using an FPS limit a few frames lower than the monitor's refresh rate will reduce input lag while avoiding tearing.

See also PhysicsTicksPerSecond and ProjectSettings "application/run/max_fps".

Note: The actual number of frames per second may still be below this value if the CPU or GPU cannot keep up with the project's logic and rendering.

Note: If ProjectSettings "display/window/vsync/vsync_mode" is Disabled, limiting the FPS to a high value that can be consistently reached on the system can reduce input lag compared to an uncapped framerate. Since this works by ensuring the GPU load is lower than 100%, this latency reduction is only effective in GPU-bottlenecked scenarios, not CPU-bottlenecked scenarios.

func MaxPhysicsStepsPerFrame

func MaxPhysicsStepsPerFrame() int

The maximum number of physics steps that can be simulated each rendered frame.

Note: The default value is tuned to prevent expensive physics simulations from triggering even more expensive simulations indefinitely. However, the game will appear to slow down if the rendering FPS is less than 1 / max_physics_steps_per_frame of PhysicsTicksPerSecond. This occurs even if delta is consistently used in physics calculations. To avoid this, increase MaxPhysicsStepsPerFrame if you have increased PhysicsTicksPerSecond significantly above its default value.

func PhysicsJitterFix

func PhysicsJitterFix() Float.X

How much physics ticks are synchronized with real time. If 0 or less, the ticks are fully synchronized. Higher values cause the in-game clock to deviate more from the real clock, but they smooth out framerate jitters.

Note: The default value of 0.5 should be good enough for most cases; values above 2 could cause the game to react to dropped frames with a noticeable delay and are not recommended.

Note: When using a custom physics interpolation solution, or within a network game, it's recommended to disable the physics jitter fix by setting this property to 0.

func PhysicsTicksPerSecond

func PhysicsTicksPerSecond() int

The number of fixed iterations per second. This controls how often physics simulation and Node.PhysicsProcess methods are run. This value should generally always be set to 60 or above, as Godot doesn't interpolate the physics step. As a result, values lower than 60 will look stuttery. This value can be increased to make input more reactive or work around collision tunneling issues, but keep in mind doing so will increase CPU usage. See also MaxFps and ProjectSettings "physics/common/physics_ticks_per_second".

Note: Only MaxPhysicsStepsPerFrame physics ticks may be simulated per rendered frame at most. If more physics ticks have to be simulated per rendered frame to keep up with rendering, the project will appear to slow down (even if delta is used consistently in physics calculations). Therefore, it is recommended to also increase MaxPhysicsStepsPerFrame if increasing PhysicsTicksPerSecond significantly above its default value.

func Print

func Print(v ...any)

Print prints one or more arguments to strings in the best way possible to the OS terminal. Unlike print, no newline is automatically added at the end.

func PrintErrorMessages

func PrintErrorMessages() bool

If false, stops printing error and warning messages to the console and editor Output log. This can be used to hide error and warning messages during unit test suite runs. This property is equivalent to the ProjectSettings "application/run/disable_stderr" project setting.

Note: This property does not impact the editor's Errors tab when running a project from the editor.

Warning: If set to false anywhere in the project, important error messages may be hidden even if they are emitted from other scripts. In a @tool script, this will also impact the editor itself. Do not report bugs before ensuring error messages are enabled (as they are by default).

func PrintRich

func PrintRich(v ...any)

PrintRich converts one or more arguments of any type to string in the best way possible and prints them to the console.

The following BBCode tags are supported: b, i, u, s, indent, code, url, center, right, color, bgcolor, fgcolor.

Color tags only support the following named colors: black, red, green, yellow, blue, magenta, pink, purple, cyan, white, orange, gray. Hexadecimal color codes are not supported.

URL tags only support URLs wrapped by a URL tag, not URLs with a different title.

When printing to standard output, the supported subset of BBCode is converted to ANSI escape codes for the terminal emulator to display. Support for ANSI escape codes varies across terminal emulators, especially for italic and strikethrough. In standard output, code is represented with faint text but without any font change. Unsupported tags are left as-is in standard output.

func PrintToStdout

func PrintToStdout() bool

If false, stops printing messages (for example using @GlobalScope.Print) to the console, log files, and editor Output log. This property is equivalent to the ProjectSettings "application/run/disable_stdout" project setting.

Note: This does not stop printing errors or warnings produced by scripts to the console or log files, for more details see PrintErrorMessages.

func Println

func Println(v ...any)

Println converts one or more arguments of any type to string in the best way possible and prints them to the console.

func Raise

func Raise(err error)

Raise pushes an error message to Godot's built-in debugger and to the OS terminal.

func RaiseWarning

func RaiseWarning(v ...any)

RaiseWarning pushes a warning message to Godot's built-in debugger and to the OS terminal.

func RegisterScriptLanguage

func RegisterScriptLanguage(language ScriptLanguage.Instance) error

Registers a ScriptLanguage instance to be available with ScriptServer.

Returns:

- [Ok] on success;

- [ErrUnavailable] if ScriptServer has reached the limit and cannot register any new language;

- [ErrAlreadyExists] if ScriptServer already contains a language with similar extension/name/type.

func RegisterSingleton

func RegisterSingleton(name string, instance Object.Instance)

Registers the given Object 'instance' as a singleton, available globally under 'name'. Useful for plugins.

func SetMaxFps

func SetMaxFps(value int)

SetMaxFps sets the property returned by [GetMaxFps].

func SetMaxPhysicsStepsPerFrame

func SetMaxPhysicsStepsPerFrame(value int)

SetMaxPhysicsStepsPerFrame sets the property returned by [GetMaxPhysicsStepsPerFrame].

func SetPhysicsJitterFix

func SetPhysicsJitterFix(value Float.X)

SetPhysicsJitterFix sets the property returned by [GetPhysicsJitterFix].

func SetPhysicsTicksPerSecond

func SetPhysicsTicksPerSecond(value int)

SetPhysicsTicksPerSecond sets the property returned by [GetPhysicsTicksPerSecond].

func SetPrintErrorMessages

func SetPrintErrorMessages(value bool)

SetPrintErrorMessages sets the property returned by [IsPrintingErrorMessages].

func SetPrintToStdout

func SetPrintToStdout(value bool)

SetPrintToStdout sets the property returned by [IsPrintingToStdout].

func SetTimeScale

func SetTimeScale(value Float.X)

SetTimeScale sets the property returned by [GetTimeScale].

func TimeScale

func TimeScale() Float.X

The speed multiplier at which the in-game clock updates, compared to real time. For example, if set to 2.0 the game runs twice as fast, and if set to 0.5 the game runs half as fast.

This value affects Timer, SceneTreeTimer, and all other simulations that make use of delta time (such as Node.Process and Node.PhysicsProcess).

Note: It's recommended to keep this property above 0.0, as the game may behave unexpectedly otherwise.

Note: This does not affect audio playback speed. Use AudioServer.PlaybackSpeedScale to adjust audio playback speed independently of Engine.TimeScale.

Note: This does not automatically adjust PhysicsTicksPerSecond. With values above 1.0 physics simulation may become less precise, as each physics tick will stretch over a larger period of engine time. If you're modifying Engine.TimeScale to speed up simulation by a large factor, consider also increasing PhysicsTicksPerSecond to make the simulation more reliable.

func UnregisterScriptLanguage

func UnregisterScriptLanguage(language ScriptLanguage.Instance) error

Unregisters the ScriptLanguage instance from ScriptServer.

Returns:

- [Ok] on success;

- [ErrDoesNotExist] if the language is not registered in ScriptServer.

func UnregisterSingleton

func UnregisterSingleton(name string)

Removes the singleton registered under 'name'. The singleton object is not freed. Only works with user-defined singletons registered with RegisterSingleton.

func Version

func Version() string

Version returns the version of the Engine.

Types

type AuthorInfo

type AuthorInfo struct {
	LeadDevelopers  []string `gd:"lead_developers"`
	Founders        []string `gd:"founders"`
	ProjectManagers []string `gd:"project_managers"`
	Developers      []string `gd:"developers"`
}

func GetAuthorInfo

func GetAuthorInfo() AuthorInfo

Returns the engine author information as a data structure, where each entry is an slice of strings with the names of notable contributors to the Godot Engine: lead_developers, founders, project_managers, and developers.

type Copyright struct {
	Name  string `gd:"name"`
	Parts []Part `gd:"parts"`
}

func GetCopyrightInfo

func GetCopyrightInfo() []Copyright

Returns an slice of dictionaries with copyright information for every component of Godot's source code.

Every data structure contains a name identifier, and a parts array of dictionaries. It describes the component in detail with the following entries:

- files - slice of file paths from the source code affected by this component;

- copyright - slice of owners of this component;

- license - The license applied to this component (such as "Expat" or "CC-BY-4.0").

type DonorInfo

type DonorInfo struct {
	PlatinumSponsors []string `gd:"platinum_sponsors"`
	GoldSponsors     []string `gd:"gold_sponsors"`
	SilverSponsors   []string `gd:"silver_sponsors"`
	BronzeSponsors   []string `gd:"bronze_sponsors"`
	MiniSponsors     []string `gd:"mini_sponsors"`
	GoldDonors       []string `gd:"gold_donors"`
	SilverDonors     []string `gd:"silver_donors"`
	BronzeDonors     []string `gd:"bronze_donors"`
}

func GetDonorInfo

func GetDonorInfo() DonorInfo

Returns a data structure of categorized donor names. Each entry is an slice of strings:

{platinum_sponsors, gold_sponsors, silver_sponsors, bronze_sponsors, mini_sponsors, gold_donors, silver_donors, bronze_donors}

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.Engine

Instance of the class with convieniently typed arguments and results.

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) ID

func (self Instance) ID() ID

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type Part

type Part struct {
	Files     []string `gd:"files"`
	Copyright []string `gd:"copyright"`
	License   string   `gd:"license"`
}

type VersionInfo

type VersionInfo struct {
	Major     int    `gd:"major"`
	Minor     int    `gd:"minor"`
	Patch     int    `gd:"patch"`
	Hex       int    `gd:"hex"`
	Status    string `gd:"status"`
	Build     string `gd:"build"`
	Hash      string `gd:"hash"`
	Timestamp int    `gd:"timestamp"`
	String    string `gd:"string"`
}

func GetVersionInfo

func GetVersionInfo() VersionInfo

Returns the current engine version information as a data structure containing the following entries:

- major - Major version number as an int;

- minor - Minor version number as an int;

- patch - Patch version number as an int;

- hex - Full version encoded as a hexadecimal int with one byte (2 hex digits) per number (see example below);

- status - Status (such as "beta", "rc1", "rc2", "stable", etc.) as a String;

- build - Build name (e.g. "custom_build") as a String;

- hash - Full Git commit hash as a String;

- timestamp - Holds the Git commit date UNIX timestamp in seconds as an int, or 0 if unavailable;

- string - major, minor, patch, status, and build in a single String.

The hex value is encoded as follows, from left to right: one byte for the major, one byte for the minor, one byte for the patch version. For example, "3.1.12" would be 0x03010C.

Note: The hex value is still an int internally, and printing it will give you its decimal representation, which is not particularly meaningful. Use hexadecimal literals for quick version comparisons from code:

if Engine.GetVersionInfo().Hex >= 0x040100 {
	// Do things specific to version 4.1 or later.
} else {
	// Do things specific to versions before 4.1.
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL