Engine

package
v0.0.0-...-d9f4d4e Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package Engine provides methods for working with Engine object instances.

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 GetArchitectureName

func GetArchitectureName() string

Returns the name of the CPU architecture the Godot binary was built for. Possible return values include [code]"x86_64"[/code], [code]"x86_32"[/code], [code]"arm64"[/code], [code]"arm32"[/code], [code]"rv64"[/code], [code]"riscv"[/code], [code]"ppc64"[/code], [code]"ppc"[/code], [code]"wasm64"[/code], and [code]"wasm32"[/code]. To detect whether the current build is 64-bit, you can use the fact that all 64-bit architecture names contain [code]64[/code] in their name: [codeblocks] [gdscript] if "64" in Engine.get_architecture_name():

print("Running a 64-bit build of Godot.")

else:

print("Running a 32-bit build of Godot.")

[/gdscript] [csharp] if (Engine.GetArchitectureName().Contains("64"))

GD.Print("Running a 64-bit build of Godot.");

else

GD.Print("Running a 32-bit build of Godot.");

[/csharp] [/codeblocks] [b]Note:[/b] This method does [i]not[/i] return the name of the system's CPU architecture (like [method OS.get_processor_name]). For example, when running an [code]x86_32[/code] Godot binary on an [code]x86_64[/code] system, the returned value will still be [code]"x86_32"[/code].

func GetFramesDrawn

func GetFramesDrawn() int

Returns the total number of frames drawn since the engine started. [b]Note:[/b] On headless platforms, or if rendering is disabled with [code]--disable-render-loop[/code] via command line, this method always returns [code]0[/code]. See also [method get_process_frames].

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 [Dictionary] of licenses used by Godot and included third party components. Each entry is a license name (such as "[url=https://en.wikipedia.org/wiki/MIT_License#Ambiguity_and_variants]Expat[/url]") and its associated text.

func GetLicenseText

func GetLicenseText() string

Returns the full Godot license text.

func GetMainLoop

func GetMainLoop() [1]gdclass.MainLoop

Returns the instance of the [MainLoop]. This is usually the main [SceneTree] and is the same as [method Node.get_tree]. [b]Note:[/b] The type instantiated as the main loop can changed with [member 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 [b]physics frame[/b]. See also [method get_process_frames]. This method can be used to run expensive logic less often without relying on a [Timer]: [codeblocks] [gdscript] func _physics_process(_delta):

if Engine.get_physics_frames() % 2 == 0:
    pass # Run expensive logic only once every 2 physics frames here.

[/gdscript] [csharp] public override void _PhysicsProcess(double delta)

{
    base._PhysicsProcess(delta);

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

[/csharp] [/codeblocks]

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 [b]process frame[/b], regardless of whether the render loop is enabled. See also [method get_frames_drawn] and [method get_physics_frames]. This method can be used to run expensive logic less often without relying on a [Timer]: [codeblocks] [gdscript] func _process(_delta):

if Engine.get_process_frames() % 5 == 0:
    pass # Run expensive logic only once every 5 process (render) frames here.

[/gdscript] [csharp] public override void _Process(double delta)

{
    base._Process(delta);

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

[/csharp] [/codeblocks]

func GetScriptLanguage

func GetScriptLanguage(index int) [1]gdclass.ScriptLanguage

Returns an instance of a [ScriptLanguage] with the given [param index].

func GetScriptLanguageCount

func GetScriptLanguageCount() int

Returns the number of available script languages. Use with [method get_script_language].

func GetSingleton

func GetSingleton(name string) Object.Instance

Returns the global singleton with the given [param name], or [code]null[/code] if it does not exist. Often used for plugins. See also [method has_singleton] and [method get_singleton_list]. [b]Note:[/b] 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 [method get_singleton].

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 [member ProjectSettings.editor/movie_writer/movie_file].

func HasSingleton

func HasSingleton(name string) bool

Returns [code]true[/code] if a singleton with the given [param name] exists in the global scope. See also [method get_singleton]. [codeblocks] [gdscript] print(Engine.has_singleton("OS")) # Prints true print(Engine.has_singleton("Engine")) # Prints true print(Engine.has_singleton("AudioServer")) # Prints true print(Engine.has_singleton("Unknown")) # Prints false [/gdscript] [csharp] GD.Print(Engine.HasSingleton("OS")); // Prints true GD.Print(Engine.HasSingleton("Engine")); // Prints true GD.Print(Engine.HasSingleton("AudioServer")); // Prints true GD.Print(Engine.HasSingleton("Unknown")); // Prints false [/csharp] [/codeblocks] [b]Note:[/b] Global singletons are not the same as autoloaded nodes, which are configurable in the project settings.

func IsEditorHint

func IsEditorHint() bool

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

draw_gizmos()

else:

simulate_physics()

[/gdscript] [csharp] if (Engine.IsEditorHint())

DrawGizmos();

else

SimulatePhysics();

[/csharp] [/codeblocks] See [url=$DOCS_URL/tutorials/plugins/running_code_in_the_editor.html]Running code in the editor[/url] in the documentation for more information. [b]Note:[/b] To detect whether the script is running on an editor [i]build[/i] (such as when pressing [kbd]F5[/kbd]), use [method OS.has_feature] with the [code]"editor"[/code] argument instead. [code]OS.has_feature("editor")[/code] evaluate to [code]true[/code] both when the script is running in the editor and when running the project from the editor, but returns [code]false[/code] when run from an exported project.

func IsInPhysicsFrame

func IsInPhysicsFrame() bool

Returns [code]true[/code] if the engine is inside the fixed physics process step of the main loop. [codeblock] func _enter_tree():

# Depending on when the node is added to the tree,
# prints either "true" or "false".
print(Engine.is_in_physics_frame())

func _process(delta):

print(Engine.is_in_physics_frame()) # Prints false

func _physics_process(delta):

print(Engine.is_in_physics_frame()) # Prints true

[/codeblock]

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

func MaxPhysicsStepsPerFrame

func MaxPhysicsStepsPerFrame() int

func PhysicsJitterFix

func PhysicsJitterFix() Float.X

func PhysicsTicksPerSecond

func PhysicsTicksPerSecond() int

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

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 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 [1]gdclass.ScriptLanguage) error

Registers a [ScriptLanguage] instance to be available with [code]ScriptServer[/code]. Returns: - [constant OK] on success; - [constant ERR_UNAVAILABLE] if [code]ScriptServer[/code] has reached the limit and cannot register any new language; - [constant ERR_ALREADY_EXISTS] if [code]ScriptServer[/code] already contains a language with similar extension/name/type.

func RegisterSingleton

func RegisterSingleton(name string, instance Object.Instance)

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

func SetMaxFps

func SetMaxFps(value int)

func SetMaxPhysicsStepsPerFrame

func SetMaxPhysicsStepsPerFrame(value int)

func SetPhysicsJitterFix

func SetPhysicsJitterFix(value Float.X)

func SetPhysicsTicksPerSecond

func SetPhysicsTicksPerSecond(value int)

func SetPrintErrorMessages

func SetPrintErrorMessages(value bool)

func SetTimeScale

func SetTimeScale(value Float.X)

func TimeScale

func TimeScale() Float.X

func UnregisterScriptLanguage

func UnregisterScriptLanguage(language [1]gdclass.ScriptLanguage) error

Unregisters the [ScriptLanguage] instance from [code]ScriptServer[/code]. Returns: - [constant OK] on success; - [constant ERR_DOES_NOT_EXIST] if the language is not registered in [code]ScriptServer[/code].

func UnregisterSingleton

func UnregisterSingleton(name string)

Removes the singleton registered under [param name]. The singleton object is [i]not[/i] freed. Only works with user-defined singletons registered with [method register_singleton].

func Version

func Version() gd.Version

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 [Dictionary], where each entry is an [Array] of strings with the names of notable contributors to the Godot Engine: [code]lead_developers[/code], [code]founders[/code], [code]project_managers[/code], and [code]developers[/code].

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

func GetCopyrightInfo

func GetCopyrightInfo() []Copyright

Returns an [Array] of dictionaries with copyright information for every component of Godot's source code. Every [Dictionary] contains a [code]name[/code] identifier, and a [code]parts[/code] array of dictionaries. It describes the component in detail with the following entries: - [code]files[/code] - [Array] of file paths from the source code affected by this component; - [code]copyright[/code] - [Array] of owners of this component; - [code]license[/code] - The license applied to this component (such as "[url=https://en.wikipedia.org/wiki/MIT_License#Ambiguity_and_variants]Expat[/url]" or "[url=https://creativecommons.org/licenses/by/4.0/]CC-BY-4.0[/url]").

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 [Dictionary] of categorized donor names. Each entry is an [Array] of strings: {[code]platinum_sponsors[/code], [code]gold_sponsors[/code], [code]silver_sponsors[/code], [code]bronze_sponsors[/code], [code]mini_sponsors[/code], [code]gold_donors[/code], [code]silver_donors[/code], [code]bronze_donors[/code]}

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 [Dictionary] containing the following entries: - [code]major[/code] - Major version number as an int; - [code]minor[/code] - Minor version number as an int; - [code]patch[/code] - Patch version number as an int; - [code]hex[/code] - Full version encoded as a hexadecimal int with one byte (2 hex digits) per number (see example below); - [code]status[/code] - Status (such as "beta", "rc1", "rc2", "stable", etc.) as a String; - [code]build[/code] - Build name (e.g. "custom_build") as a String; - [code]hash[/code] - Full Git commit hash as a String; - [code]timestamp[/code] - Holds the Git commit date UNIX timestamp in seconds as an int, or [code]0[/code] if unavailable; - [code]string[/code] - [code]major[/code], [code]minor[/code], [code]patch[/code], [code]status[/code], and [code]build[/code] in a single String. The [code]hex[/code] 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 [code]0x03010C[/code]. [b]Note:[/b] The [code]hex[/code] 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: [codeblocks] [gdscript] if Engine.get_version_info().hex >= 0x040100:

pass # Do things specific to version 4.1 or later.

else:

pass # Do things specific to versions before 4.1.

[/gdscript] [csharp] if ((int)Engine.GetVersionInfo()["hex"] >= 0x040100)

{
    // Do things specific to version 4.1 or later.
}

else

{
    // Do things specific to versions before 4.1.
}

[/csharp] [/codeblocks]

Jump to

Keyboard shortcuts

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