Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Engine

Hérite de : Object

Fournit un accès aux propriétés du moteur.

Description

Le singleton Engine vous permet d'interroger et de modifier les paramètres d'exécution du projet, comme les trames par seconde, l'échelle de temps et d'autres. Il stocke également des informations sur la compilation actuelle de Godot, comme la version actuelle.

Propriétés

int

max_fps

0

int

max_physics_steps_per_frame

8

float

physics_jitter_fix

0.5

int

physics_ticks_per_second

60

bool

print_error_messages

true

bool

print_to_stdout

true

float

time_scale

1.0

Méthodes

Array[ScriptBacktrace]

capture_script_backtraces(include_variables: bool = false) const

String

get_architecture_name() const

Dictionary

get_author_info() const

Array[Dictionary]

get_copyright_info() const

Dictionary

get_donor_info() const

int

get_frames_drawn()

float

get_frames_per_second() const

Dictionary

get_license_info() const

String

get_license_text() const

MainLoop

get_main_loop() const

int

get_physics_frames() const

float

get_physics_interpolation_fraction() const

int

get_process_frames() const

ScriptLanguage

get_script_language(index: int) const

int

get_script_language_count()

Object

get_singleton(name: StringName) const

PackedStringArray

get_singleton_list() const

Dictionary

get_version_info() const

String

get_write_movie_path() const

bool

has_singleton(name: StringName) const

bool

is_editor_hint() const

bool

is_embedded_in_editor() const

bool

is_in_physics_frame() const

Error

register_script_language(language: ScriptLanguage)

void

register_singleton(name: StringName, instance: Object)

Error

unregister_script_language(language: ScriptLanguage)

void

unregister_singleton(name: StringName)


Descriptions des propriétés

int max_fps = 0 🔗

  • void set_max_fps(value: int)

  • int get_max_fps()

Le nombre maximal d'images qui peuvent être rendues chaque seconde (FPS). Une valeur de 0 signifie que le framerate n'est pas limité.

Limiter les FPS peut être utile pour réduire la consommation d'énergie de la machine hôte, ce qui réduit la chaleur, les émissions sonores et améliore la durée de vie de la batterie.

Si ProjectSettings.display/window/vsync/vsync_mode vaut Enabled ou Adaptive, le paramètre a priorité et le nombre max de FPS ne peut dépasser le taux de rafraîchissement du moniteur. Voir aussi DisplayServer.screen_get_refresh_rate().

Si ProjectSettings.display/window/vsync/vsync_mode vaut Enabled, sur les moniteurs à taux de rafraîchissement variable (G-Sync/FreeSync), en utilisant une limite de FPS inférieure de quelques images à la vitesse de rafraîchissement du moniteur réduit l'imput lag tout en évitant les déchirures. Sur des taux de rafraîchissement plus élevés, il faudrait accroître la différence entre la limite de FPS et le taux de rafraîchissement du moniteur afin de tenir compte des inexactitudes temporelles. La formule optimale pour la valeur limite des FPS dans ce scénario est r - (r * r) / 3600.0, où r est le taux de rafraîchissement du moniteur.

Note : Le nombre réel d'images par seconde peut encore être inférieur à cette valeur si le CPU ou le GPU ne peut pas respecter la logique et le rendu du projet.

Note : Si ProjectSettings.display/window/vsync/vsync_mode vaut Disabled, limiter les FPS à une valeur élevée qui peut être constamment atteinte sur le système peut réduire l'imput lag par rapport à un framerate non plafonné. Comme cela fonctionne en veillant à ce que la charge GPU soit inférieure à 100%, cette réduction de latence n'est efficace que dans les scénarios limités par le GPU, et non dans les scénarios limités par le CPU.


int max_physics_steps_per_frame = 8 🔗

  • void set_max_physics_steps_per_frame(value: int)

  • int get_max_physics_steps_per_frame()

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 physics_ticks_per_second. This occurs even if delta is consistently used in physics calculations. To avoid this, increase max_physics_steps_per_frame if you have increased physics_ticks_per_second significantly above its default value.


float physics_jitter_fix = 0.5 🔗

  • void set_physics_jitter_fix(value: float)

  • float get_physics_jitter_fix()

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.


int physics_ticks_per_second = 60 🔗

  • void set_physics_ticks_per_second(value: int)

  • int get_physics_ticks_per_second()

Le nombre d'itérations fixes par seconde. Cela contrôle combien de fois la simulation physique et la méthode Node._physics_process() sont exécutées.

L'utilisation du processeur augmente linéairement avec le taux de tic physique. Cependant, à des taux de tic très faibles (généralement inférieurs à 30), le comportement physique peut se décomposer. L'entrée peut également devenir moins sensible à des taux de tic faibles car il peut y avoir un écart entre l'entrée étant enregistrée, et la réponse sur la prochaine tic de physique. Des taux de tic élevés donnent une simulation physique plus précise, en particulier pour les objets en mouvement rapide. Par exemple, les jeux de course peuvent bénéficier d'augmenter le taux de tics au-dessus du taux par défaut de 60.

Voir aussi max_fps et ProjectSettings.physics/common/physics_ticks_per_second.

Note : Seul les tics physiques max_physics_steps_per_frame peuvent être simulées par trame visuelle rendue au maximum. Si des tics physiques suplémentaires doivent être simulées pour maintenir le rendu, le projet semblera ralentir (même si delta est utilisé systématiquement dans les calculs de physique). Par conséquent, il est recommandé d'augmenter max_physics_steps_per_frame si vous augmentez physics_ticks_per_second significativement au-dessus de sa valeur par défaut.

Note: Envisager d'activer l'interpolation de la physique si vous changez physics_ticks_per_second à une valeur qui n'est pas multiple de 60. L'utilisation de l'interpolation de la physique évitera les déchirements lorsque le taux de rafraîchissement du moniteur et le taux de mise à jour de la physique ne correspondent pas exactement.


bool print_error_messages = true 🔗

  • void set_print_error_messages(value: bool)

  • bool is_printing_error_messages()

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).


bool print_to_stdout = true 🔗

  • void set_print_to_stdout(value: bool)

  • bool is_printing_to_stdout()

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 print_error_messages.


float time_scale = 1.0 🔗

  • void set_time_scale(value: float)

  • float get_time_scale()

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._physics_process()).

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.playback_speed_scale to adjust audio playback speed independently of time_scale.

Note: This does not automatically adjust physics_ticks_per_second. 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 time_scale to speed up simulation by a large factor, consider also increasing physics_ticks_per_second to make the simulation more reliable.


Descriptions des méthodes

Array[ScriptBacktrace] capture_script_backtraces(include_variables: bool = false) const 🔗

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.


String get_architecture_name() const 🔗

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.has_feature() 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.get_processor_name()). For example, when running an x86_32 Godot binary on an x86_64 system, the returned value will still be "x86_32".


Dictionary get_author_info() const 🔗

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: lead_developers, founders, project_managers, and developers.


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

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

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

  • copyright - Array of owners of this component;

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


Dictionary get_donor_info() const 🔗

Renvoie un Dictionary des noms catégorisés de donneurs. Chaque entrée est un Array de chaînes :

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


int get_frames_drawn() 🔗

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 get_process_frames().


float get_frames_per_second() const 🔗

Renvoie le nombre moyen de trames rendues chaque seconde (FPS), également connu comme le framerate.


Dictionary get_license_info() const 🔗

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


String get_license_text() const 🔗

Renvoie le texte complet de la licence Godot.


MainLoop get_main_loop() const 🔗

Returns the instance of the MainLoop. This is usually the main SceneTree and is the same as Node.get_tree().

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


int get_physics_frames() const 🔗

Renvoie le nombre de trames écoulées depuis le démarrage du moteur. Ce nombre est incrémenté à chaque nouvelle trame physique. Voir aussi get_process_frames().

Cette méthode peut être utilisée pour lancer des logiques coûteuses moins souvent sans utiliser un Timer :

func _physics_process(_delta):
    if Engine.get_physics_frames() % 2 == 0:
        pass # Exécutez la logique coûteuse qu'une trame physique sur 2 ici.

float get_physics_interpolation_fraction() const 🔗

Renvoie la fraction du tic de physique actuel auquel nous sommes au moment de rendre la trame. Cela peut être utilisé pour implémenter une interpolation à différentiel de temps fixe.


int get_process_frames() const 🔗

Renvoie le nombre total de trames passées depuis le démarrage du moteur. Ce nombre est augmenté à chaque trame de traitement, peu importe si la boucle de rendu est activée. Voir aussi get_frames_drawn() et get_physics_frames().

Cette méthode peut être utilisée pour exécuter une logique coûteuse moins souvent sans compter sur un Timer :

func _process(_delta):
    if Engine.get_process_frames() % 5 == 0:
        pass # Exécutez une logique coûteuse seulement une fois tous les 5 cadres de traitement (rendu) ici.

ScriptLanguage get_script_language(index: int) const 🔗

Renvoie une instance d'un ScriptLanguage avec l'index index donné.


int get_script_language_count() 🔗

Renvoie le nombre de langages de script disponibles. À utiliser avec get_script_language().


Object get_singleton(name: StringName) const 🔗

Returns the global singleton with the given name, or null if it does not exist. Often used for plugins. See also has_singleton() and get_singleton_list().

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


PackedStringArray get_singleton_list() const 🔗

Renvoie une liste des noms de tous les singletons globaux disponibles. Voir aussi get_singleton().


Dictionary get_version_info() const 🔗

Renvoie les informations sur la version actuelle du moteur dans un Dictionary contenant les entrées suivantes :

  • major - Le numéro de version majeur en tant qu'entier int

  • minor - Le numéro de version mineur en tant qu'entier int

  • patch - Le numéro de version de correctif en tant qu'entier int

  • hex - Le numéro complet de version sous forme d'entier au format hexadécimal avec un octet (2 caractères) par numéro (voir l'exemple en-dessous)

  • status - Le status (ex. : "beta", "rc1", "rc2", "stable", etc...) en chaîne de caractères String

  • build - Le nom de la version (ex. : "custom_build") en chaîne de caractères String

  • hash - Le hachage du commit Git en tant que chaîne de caractère String

  • timestamp - Contient le timestamp UNIX de la date du commit Git en secondes en tant qu'entier int, ou 0 si indisponible

  • string - major, minor, patch, status et build dans un seule chaîne String.

La valeur hex est codée comme suit, de gauche à droite : un octet pour le numéro majeur, un octet pour le numéro mineur, un octet pour le numéro de correctif. Par exemple, la "3.1.12" sera la valeur 0x03010C.

Note : La valeur hex est toujours un int en interne, et l'afficher donnera sa représentation décimale qui ne sera pas particulièrement utile. Utilisez une représentation hexadécimale permet de facilement comparer les versions dans le code :

if Engine.get_version_info().hex >= 0x040100:
    pass # Faire des choses spécifiques à la version 4.1 et plus.
else:
    pass # Faire des choses spécifiques aux versions avant la 4.1.

String get_write_movie_path() const 🔗

Renvoie le chemin vers le fichier de sortie MovieWriter, ou une chaîne vide si le moteur n'a pas été lancé en mode Création de film. Le chemin par défaut peut être modifié dans ProjectSettings.editor/movie_writer/movie_file.


bool has_singleton(name: StringName) const 🔗

Returns true if a singleton with the given name exists in the global scope. See also get_singleton().

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

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


bool is_editor_hint() const 🔗

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.is_editor_hint():
    draw_gizmos()
else:
    simulate_physics()

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.has_feature() 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.


bool is_embedded_in_editor() const 🔗

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.


bool is_in_physics_frame() const 🔗

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

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

Error register_script_language(language: ScriptLanguage) 🔗

Registers a ScriptLanguage instance to be available with ScriptServer.

Returns:


void register_singleton(name: StringName, instance: Object) 🔗

Enregistre l'instance d'Object donnée comme un singleton, disponible globalement sous le nom name. Utile pour les plugins.


Error unregister_script_language(language: ScriptLanguage) 🔗

Unregisters the ScriptLanguage instance from ScriptServer.

Returns:


void unregister_singleton(name: StringName) 🔗

Retire le singleton enregistré sous le nom name. L'objet singleton n'est pas libéré. Fonctionne seulement avec des singletons définis par l'utilisateur et enregistrés avec register_singleton().