Up to date

This page is up to date for Godot 4.1. If you still find outdated information, please open an issue.

Object

Inherited By: AudioServer, CameraServer, ClassDB, DisplayServer, EditorFileSystemDirectory, EditorInterface, EditorPaths, EditorSelection, EditorUndoRedoManager, EditorVCSInterface, Engine, EngineDebugger, GDExtensionManager, Geometry2D, Geometry3D, GodotSharp, Input, InputMap, IP, JavaClassWrapper, JavaScriptBridge, JNISingleton, JSONRPC, MainLoop, Marshalls, MovieWriter, NavigationMeshGenerator, NavigationServer2D, NavigationServer3D, Node, OS, Performance, PhysicsDirectBodyState2D, PhysicsDirectBodyState3D, PhysicsDirectSpaceState2D, PhysicsDirectSpaceState3D, PhysicsServer2D, PhysicsServer2DManager, PhysicsServer3D, PhysicsServer3DManager, PhysicsServer3DRenderingServerHandler, ProjectSettings, RefCounted, RenderingDevice, RenderingServer, ResourceLoader, ResourceSaver, ResourceUID, ScriptLanguage, TextServerManager, ThemeDB, TileData, Time, TranslationServer, TreeItem, UndoRedo, WorkerThreadPool, XRServer

Base class for all other classes in the engine.

Description

An advanced Variant type. All classes in the engine inherit from Object. Each class may define new properties, methods or signals, which are available to all inheriting classes. For example, a Sprite2D instance is able to call Node.add_child because it inherits from Node.

You can create new instances, using Object.new() in GDScript, or new Object in C#.

To delete an Object instance, call free. This is necessary for most classes inheriting Object, because they do not manage memory on their own, and will otherwise cause memory leaks when no longer in use. There are a few classes that perform memory management. For example, RefCounted (and by extension Resource) deletes itself when no longer referenced, and Node deletes its children when freed.

Objects can have a Script attached to them. Once the Script is instantiated, it effectively acts as an extension to the base class, allowing it to define and inherit new properties, methods and signals.

Inside a Script, _get_property_list may be overridden to customize properties in several ways. This allows them to be available to the editor, display as lists of options, sub-divide into groups, save on disk, etc. Scripting languages offer easier ways to customize properties, such as with the @GDScript.@export annotation.

Godot is very dynamic. An object’s script, and therefore its properties, methods and signals, can be changed at run-time. Because of this, there can be occasions where, for example, a property required by a method may not exist. To prevent run-time errors, see methods such as set, get, call, has_method, has_signal, etc. Note that these methods are much slower than direct references.

In GDScript, you can also check if a given property, method, or signal name exists in an object with the in operator:

  1. var node = Node.new()
  2. print("name" in node) # Prints true
  3. print("get_parent" in node) # Prints true
  4. print("tree_entered" in node) # Prints true
  5. print("unknown" in node) # Prints false

Notifications are int constants commonly sent and received by objects. For example, on every rendered frame, the SceneTree notifies nodes inside the tree with a Node.NOTIFICATION_PROCESS. The nodes receive it and may call Node._process to update. To make use of notifications, see notification and _notification.

Lastly, every object can also contain metadata (data about data). set_meta can be useful to store information that the object itself does not depend on. To keep your code clean, making excessive use of metadata is discouraged.

Note: Unlike references to a RefCounted, references to an object stored in a variable can become invalid without being set to null. To check if an object has been deleted, do not compare it against null. Instead, use @GlobalScope.is_instance_valid. It’s also recommended to inherit from RefCounted for classes storing data instead of Object.

Note: The script is not exposed like most properties. To set or get an object’s Script in code, use set_script and get_script, respectively.

Tutorials

Methods

Variant

_get ( StringName property ) virtual

Dictionary[]

_get_property_list ( ) virtual

void

_init ( ) virtual

void

_notification ( int what ) virtual

bool

_property_can_revert ( StringName property ) virtual

Variant

_property_get_revert ( StringName property ) virtual

bool

_set ( StringName property, Variant value ) virtual

String

_to_string ( ) virtual

void

add_user_signal ( String signal, Array arguments=[] )

Variant

call ( StringName method, … ) vararg

Variant

call_deferred ( StringName method, … ) vararg

Variant

callv ( StringName method, Array arg_array )

bool

can_translate_messages ( ) const

void

cancel_free ( )

Error

connect ( StringName signal, Callable callable, int flags=0 )

void

disconnect ( StringName signal, Callable callable )

Error

emit_signal ( StringName signal, … ) vararg

void

free ( )

Variant

get ( StringName property ) const

String

get_class ( ) const

Dictionary[]

get_incoming_connections ( ) const

Variant

get_indexed ( NodePath property_path ) const

int

get_instance_id ( ) const

Variant

get_meta ( StringName name, Variant default=null ) const

StringName[]

get_meta_list ( ) const

Dictionary[]

get_method_list ( ) const

Dictionary[]

get_property_list ( ) const

Variant

get_script ( ) const

Dictionary[]

get_signal_connection_list ( StringName signal ) const

Dictionary[]

get_signal_list ( ) const

bool

has_meta ( StringName name ) const

bool

has_method ( StringName method ) const

bool

has_signal ( StringName signal ) const

bool

has_user_signal ( StringName signal ) const

bool

is_blocking_signals ( ) const

bool

is_class ( String class ) const

bool

is_connected ( StringName signal, Callable callable ) const

bool

is_queued_for_deletion ( ) const

void

notification ( int what, bool reversed=false )

void

notify_property_list_changed ( )

bool

property_can_revert ( StringName property ) const

Variant

property_get_revert ( StringName property ) const

void

remove_meta ( StringName name )

void

set ( StringName property, Variant value )

void

set_block_signals ( bool enable )

void

set_deferred ( StringName property, Variant value )

void

set_indexed ( NodePath property_path, Variant value )

void

set_message_translation ( bool enable )

void

set_meta ( StringName name, Variant value )

void

set_script ( Variant script )

String

to_string ( )

String

tr ( StringName message, StringName context=”” ) const

String

tr_n ( StringName message, StringName plural_message, int n, StringName context=”” ) const


Signals

property_list_changed ( )

Emitted when notify_property_list_changed is called.


script_changed ( )

Emitted when the object’s script is changed.

Note: When this signal is emitted, the new script is not initialized yet. If you need to access the new script, defer connections to this signal with CONNECT_DEFERRED.


Enumerations

enum ConnectFlags:

ConnectFlags CONNECT_DEFERRED = 1

Deferred connections trigger their Callables on idle time (at the end of the frame), rather than instantly.

ConnectFlags CONNECT_PERSIST = 2

Persisting connections are stored when the object is serialized (such as when using PackedScene.pack). In the editor, connections created through the Node dock are always persisting.

ConnectFlags CONNECT_ONE_SHOT = 4

One-shot connections disconnect themselves after emission.

ConnectFlags CONNECT_REFERENCE_COUNTED = 8

Reference-counted connections can be assigned to the same Callable multiple times. Each disconnection decreases the internal counter. The signal fully disconnects only when the counter reaches 0.


Constants

NOTIFICATION_POSTINITIALIZE = 0

Notification received when the object is initialized, before its script is attached. Used internally.

NOTIFICATION_PREDELETE = 1

Notification received when the object is about to be deleted. Can act as the deconstructor of some programming languages.


Method Descriptions

Variant _get ( StringName property ) virtual

Override this method to customize the behavior of get. Should return the given property‘s value, or null if the property should be handled normally.

Combined with _set and _get_property_list, this method allows defining custom properties, which is particularly useful for editor plugins. Note that a property must be present in get_property_list, otherwise this method will not be called.

GDScriptC#

  1. func _get(property):
  2. if (property == "fake_property"):
  3. print("Getting my property!")
  4. return 4
  5. func _get_property_list():
  6. return [
  7. { "name": "fake_property", "type": TYPE_INT }
  8. ]
  1. public override Variant _Get(StringName property)
  2. {
  3. if (property == "FakeProperty")
  4. {
  5. GD.Print("Getting my property!");
  6. return 4;
  7. }
  8. return default;
  9. }
  10. public override Godot.Collections.Array<Godot.Collections.Dictionary> _GetPropertyList()
  11. {
  12. return new Godot.Collections.Array<Godot.Collections.Dictionary>()
  13. {
  14. new Godot.Collections.Dictionary()
  15. {
  16. { "name", "FakeProperty" },
  17. { "type", (int)Variant.Type.Int }
  18. }
  19. };
  20. }

Dictionary[] _get_property_list ( ) virtual

Override this method to customize how script properties should be handled by the engine.

Should return a property list, as an Array of dictionaries. The result is added to the array of get_property_list, and should be formatted in the same way. Each Dictionary must at least contain the name and type entries.

The example below displays hammer_type in the Inspector dock, only if holding_hammer is true:

GDScriptC#

  1. @tool
  2. extends Node2D
  3. @export var holding_hammer = false:
  4. set(value):
  5. holding_hammer = value
  6. notify_property_list_changed()
  7. var hammer_type = 0
  8. func _get_property_list():
  9. # By default, `hammer_type` is not visible in the editor.
  10. var property_usage = PROPERTY_USAGE_NO_EDITOR
  11. if holding_hammer:
  12. property_usage = PROPERTY_USAGE_DEFAULT
  13. var properties = []
  14. properties.append({
  15. "name": "hammer_type",
  16. "type": TYPE_INT,
  17. "usage": property_usage, # See above assignment.
  18. "hint": PROPERTY_HINT_ENUM,
  19. "hint_string": "Wooden,Iron,Golden,Enchanted"
  20. })
  21. return properties
  1. [Tool]
  2. public partial class MyNode2D : Node2D
  3. {
  4. private bool _holdingHammer;
  5. [Export]
  6. public bool HoldingHammer
  7. {
  8. get => _holdingHammer;
  9. set
  10. {
  11. _holdingHammer = value;
  12. NotifyPropertyListChanged();
  13. }
  14. }
  15. public int HammerType { get; set; }
  16. public override Godot.Collections.Array<Godot.Collections.Dictionary> _GetPropertyList()
  17. {
  18. // By default, `HammerType` is not visible in the editor.
  19. var propertyUsage = PropertyUsageFlags.NoEditor;
  20. if (HoldingHammer)
  21. {
  22. propertyUsage = PropertyUsageFlags.Default;
  23. }
  24. var properties = new Godot.Collections.Array<Godot.Collections.Dictionary>();
  25. properties.Add(new Godot.Collections.Dictionary()
  26. {
  27. { "name", "HammerType" },
  28. { "type", (int)Variant.Type.Int },
  29. { "usage", (int)propertyUsage }, // See above assignment.
  30. { "hint", (int)PropertyHint.Enum },
  31. { "hint_string", "Wooden,Iron,Golden,Enchanted" }
  32. });
  33. return properties;
  34. }
  35. }

Note: This method is intended for advanced purposes. For most common use cases, the scripting languages offer easier ways to handle properties. See @GDScript.@export, @GDScript.@export_enum, @GDScript.@export_group, etc.

Note: If the object’s script is not @GDScript.@tool, this method will not be called in the editor.


void _init ( ) virtual

Called when the object’s script is instantiated, oftentimes after the object is initialized in memory (through Object.new() in GDScript, or new Object in C#). It can be also defined to take in parameters. This method is similar to a constructor in most programming languages.

Note: If _init is defined with required parameters, the Object with script may only be created directly. If any other means (such as PackedScene.instantiate or Node.duplicate) are used, the script’s initialization will fail.


void _notification ( int what ) virtual

Called when the object receives a notification, which can be identified in what by comparing it with a constant. See also notification.

GDScriptC#

  1. func _notification(what):
  2. if what == NOTIFICATION_PREDELETE:
  3. print("Goodbye!")
  1. public override void _Notification(int what)
  2. {
  3. if (what == NotificationPredelete)
  4. {
  5. GD.Print("Goodbye!");
  6. }
  7. }

Note: The base Object defines a few notifications (NOTIFICATION_POSTINITIALIZE and NOTIFICATION_PREDELETE). Inheriting classes such as Node define a lot more notifications, which are also received by this method.


bool _property_can_revert ( StringName property ) virtual

Override this method to customize the given property‘s revert behavior. Should return true if the property can be reverted in the Inspector dock. Use _property_get_revert to specify the property‘s default value.

Note: This method must return consistently, regardless of the current value of the property.


Variant _property_get_revert ( StringName property ) virtual

Override this method to customize the given property‘s revert behavior. Should return the default value for the property. If the default value differs from the property‘s current value, a revert icon is displayed in the Inspector dock.

Note: _property_can_revert must also be overridden for this method to be called.


bool _set ( StringName property, Variant value ) virtual

Override this method to customize the behavior of set. Should set the property to value and return true, or false if the property should be handled normally. The exact way to set the property is up to this method’s implementation.

Combined with _get and _get_property_list, this method allows defining custom properties, which is particularly useful for editor plugins. Note that a property must be present in get_property_list, otherwise this method will not be called.

GDScriptC#

  1. func _set(property, value):
  2. if (property == "fake_property"):
  3. print("Setting my property to ", value)
  4. func _get_property_list():
  5. return [
  6. { "name": "fake_property", "type": TYPE_INT }
  7. ]
  1. public override void _Set(StringName property, Variant value)
  2. {
  3. if (property == "FakeProperty")
  4. {
  5. GD.Print($"Setting my property to {value}");
  6. return true;
  7. }
  8. return false;
  9. }
  10. public override Godot.Collections.Array<Godot.Collections.Dictionary> _GetPropertyList()
  11. {
  12. return new Godot.Collections.Array<Godot.Collections.Dictionary>()
  13. {
  14. new Godot.Collections.Dictionary()
  15. {
  16. { "name", "FakeProperty" },
  17. { "type", (int)Variant.Type.Int }
  18. }
  19. };
  20. }

String _to_string ( ) virtual

Override this method to customize the return value of to_string, and therefore the object’s representation as a String.

  1. func _to_string():
  2. return "Welcome to Godot 4!"
  3. func _init():
  4. print(self) # Prints Welcome to Godot 4!"
  5. var a = str(self) # a is "Welcome to Godot 4!"

void add_user_signal ( String signal, Array arguments=[] )

Adds a user-defined signal. Optional arguments for the signal can be added as an Array of dictionaries, each defining a name String and a type int (see Variant.Type). See also has_user_signal.

GDScriptC#

  1. add_user_signal("hurt", [
  2. { "name": "damage", "type": TYPE_INT },
  3. { "name": "source", "type": TYPE_OBJECT }
  4. ])
  1. AddUserSignal("Hurt", new Godot.Collections.Array()
  2. {
  3. new Godot.Collections.Dictionary()
  4. {
  5. { "name", "damage" },
  6. { "type", (int)Variant.Type.Int }
  7. },
  8. new Godot.Collections.Dictionary()
  9. {
  10. { "name", "source" },
  11. { "type", (int)Variant.Type.Object }
  12. }
  13. });

Variant call ( StringName method, … ) vararg

Calls the method on the object and returns the result. This method supports a variable number of arguments, so parameters can be passed as a comma separated list.

GDScriptC#

  1. var node = Node3D.new()
  2. node.call("rotate", Vector3(1.0, 0.0, 0.0), 1.571)
  1. var node = new Node3D();
  2. node.Call(Node3D.MethodName.Rotate, new Vector3(1f, 0f, 0f), 1.571f);

Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.


Variant call_deferred ( StringName method, … ) vararg

Calls the method on the object during idle time. Always returns null, not the method’s result.

Idle time happens mainly at the end of process and physics frames. In it, deferred calls will be run until there are none left, which means you can defer calls from other deferred calls and they’ll still be run in the current idle time cycle. If not done carefully, this can result in infinite recursion without causing a stack overflow, which will hang the game similarly to an infinite loop.

This method supports a variable number of arguments, so parameters can be passed as a comma separated list.

GDScriptC#

  1. var node = Node3D.new()
  2. node.call_deferred("rotate", Vector3(1.0, 0.0, 0.0), 1.571)
  1. var node = new Node3D();
  2. node.CallDeferred(Node3D.MethodName.Rotate, new Vector3(1f, 0f, 0f), 1.571f);

See also Callable.call_deferred.

Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.

Note: If you’re looking to delay the function call by a frame, refer to the SceneTree.process_frame and SceneTree.physics_frame signals.

  1. var node = Node3D.new()
  2. # Make a Callable and bind the arguments to the node's rotate() call.
  3. var callable = node.rotate.bind(Vector3(1.0, 0.0, 0.0), 1.571)
  4. # Connect the callable to the process_frame signal, so it gets called in the next process frame.
  5. # CONNECT_ONE_SHOT makes sure it only gets called once instead of every frame.
  6. get_tree().process_frame.connect(callable, CONNECT_ONE_SHOT)

Variant callv ( StringName method, Array arg_array )

Calls the method on the object and returns the result. Unlike call, this method expects all parameters to be contained inside arg_array.

GDScriptC#

  1. var node = Node3D.new()
  2. node.callv("rotate", [Vector3(1.0, 0.0, 0.0), 1.571])
  1. var node = new Node3D();
  2. node.Callv(Node3D.MethodName.Rotate, new Godot.Collections.Array { new Vector3(1f, 0f, 0f), 1.571f });

Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.


bool can_translate_messages ( ) const

Returns true if the object is allowed to translate messages with tr and tr_n. See also set_message_translation.


void cancel_free ( )

If this method is called during NOTIFICATION_PREDELETE, this object will reject being freed and will remain allocated. This is mostly an internal function used for error handling to avoid the user from freeing objects when they are not intended to.


Error connect ( StringName signal, Callable callable, int flags=0 )

Connects a signal by name to a callable. Optional flags can be also added to configure the connection’s behavior (see ConnectFlags constants).

A signal can only be connected once to the same Callable. If the signal is already connected, this method returns @GlobalScope.ERR_INVALID_PARAMETER and pushes an error message, unless the signal is connected with CONNECT_REFERENCE_COUNTED. To prevent this, use is_connected first to check for existing connections.

If the callable‘s object is freed, the connection will be lost.

Examples with recommended syntax:

Connecting signals is one of the most common operations in Godot and the API gives many options to do so, which are described further down. The code block below shows the recommended approach.

GDScriptC#

  1. func _ready():
  2. var button = Button.new()
  3. # `button_down` here is a Signal variant type, and we thus call the Signal.connect() method, not Object.connect().
  4. # See discussion below for a more in-depth overview of the API.
  5. button.button_down.connect(_on_button_down)
  6. # This assumes that a `Player` class exists, which defines a `hit` signal.
  7. var player = Player.new()
  8. # We use Signal.connect() again, and we also use the Callable.bind() method,
  9. # which returns a new Callable with the parameter binds.
  10. player.hit.connect(_on_player_hit.bind("sword", 100))
  11. func _on_button_down():
  12. print("Button down!")
  13. func _on_player_hit(weapon_type, damage):
  14. print("Hit with weapon %s for %d damage." % [weapon_type, damage])
  1. public override void _Ready()
  2. {
  3. var button = new Button();
  4. // C# supports passing signals as events, so we can use this idiomatic construct:
  5. button.ButtonDown += OnButtonDown;
  6. // This assumes that a `Player` class exists, which defines a `Hit` signal.
  7. var player = new Player();
  8. // We can use lambdas when we need to bind additional parameters.
  9. player.Hit += () => OnPlayerHit("sword", 100);
  10. }
  11. private void OnButtonDown()
  12. {
  13. GD.Print("Button down!");
  14. }
  15. private void OnPlayerHit(string weaponType, int damage)
  16. {
  17. GD.Print($"Hit with weapon {weaponType} for {damage} damage.");
  18. }

``Object.connect()`` or ``Signal.connect()``?

As seen above, the recommended method to connect signals is not connect. The code block below shows the four options for connecting signals, using either this legacy method or the recommended Signal.connect, and using either an implicit Callable or a manually defined one.

GDScriptC#

  1. func _ready():
  2. var button = Button.new()
  3. # Option 1: Object.connect() with an implicit Callable for the defined function.
  4. button.connect("button_down", _on_button_down)
  5. # Option 2: Object.connect() with a constructed Callable using a target object and method name.
  6. button.connect("button_down", Callable(self, "_on_button_down"))
  7. # Option 3: Signal.connect() with an implicit Callable for the defined function.
  8. button.button_down.connect(_on_button_down)
  9. # Option 4: Signal.connect() with a constructed Callable using a target object and method name.
  10. button.button_down.connect(Callable(self, "_on_button_down"))
  11. func _on_button_down():
  12. print("Button down!")
  1. public override void _Ready()
  2. {
  3. var button = new Button();
  4. // Option 1: In C#, we can use signals as events and connect with this idiomatic syntax:
  5. button.ButtonDown += OnButtonDown;
  6. // Option 2: GodotObject.Connect() with a constructed Callable from a method group.
  7. button.Connect(Button.SignalName.ButtonDown, Callable.From(OnButtonDown));
  8. // Option 3: GodotObject.Connect() with a constructed Callable using a target object and method name.
  9. button.Connect(Button.SignalName.ButtonDown, new Callable(this, MethodName.OnButtonDown));
  10. }
  11. private void OnButtonDown()
  12. {
  13. GD.Print("Button down!");
  14. }

While all options have the same outcome (button‘s BaseButton.button_down signal will be connected to _on_button_down), option 3 offers the best validation: it will print a compile-time error if either the button_down Signal or the _on_button_down Callable are not defined. On the other hand, option 2 only relies on string names and will only be able to validate either names at runtime: it will print a runtime error if "button_down" doesn’t correspond to a signal, or if "_on_button_down" is not a registered method in the object self. The main reason for using options 1, 2, or 4 would be if you actually need to use strings (e.g. to connect signals programmatically based on strings read from a configuration file). Otherwise, option 3 is the recommended (and fastest) method.

Binding and passing parameters:

The syntax to bind parameters is through Callable.bind, which returns a copy of the Callable with its parameters bound.

When calling emit_signal, the signal parameters can be also passed. The examples below show the relationship between these signal parameters and bound parameters.

GDScriptC#

  1. func _ready():
  2. # This assumes that a `Player` class exists, which defines a `hit` signal.
  3. var player = Player.new()
  4. # Using Callable.bind().
  5. player.hit.connect(_on_player_hit.bind("sword", 100))
  6. # Parameters added when emitting the signal are passed first.
  7. player.emit_signal("hit", "Dark lord", 5)
  8. # We pass two arguments when emitting (`hit_by`, `level`),
  9. # and bind two more arguments when connecting (`weapon_type`, `damage`).
  10. func _on_player_hit(hit_by, level, weapon_type, damage):
  11. print("Hit by %s (level %d) with weapon %s for %d damage." % [hit_by, level, weapon_type, damage])
  1. public override void _Ready()
  2. {
  3. // This assumes that a `Player` class exists, which defines a `Hit` signal.
  4. var player = new Player();
  5. // Using lambda expressions that create a closure that captures the additional parameters.
  6. // The lambda only receives the parameters defined by the signal's delegate.
  7. player.Hit += (hitBy, level) => OnPlayerHit(hitBy, level, "sword", 100);
  8. // Parameters added when emitting the signal are passed first.
  9. player.EmitSignal(SignalName.Hit, "Dark lord", 5);
  10. }
  11. // We pass two arguments when emitting (`hit_by`, `level`),
  12. // and bind two more arguments when connecting (`weapon_type`, `damage`).
  13. private void OnPlayerHit(string hitBy, int level, string weaponType, int damage)
  14. {
  15. GD.Print($"Hit by {hitBy} (level {level}) with weapon {weaponType} for {damage} damage.");
  16. }

void disconnect ( StringName signal, Callable callable )

Disconnects a signal by name from a given callable. If the connection does not exist, generates an error. Use is_connected to make sure that the connection exists.


Error emit_signal ( StringName signal, … ) vararg

Emits the given signal by name. The signal must exist, so it should be a built-in signal of this class or one of its inherited classes, or a user-defined signal (see add_user_signal). This method supports a variable number of arguments, so parameters can be passed as a comma separated list.

Returns @GlobalScope.ERR_UNAVAILABLE if signal does not exist or the parameters are invalid.

GDScriptC#

  1. emit_signal("hit", "sword", 100)
  2. emit_signal("game_over")
  1. EmitSignal(SignalName.Hit, "sword", 100);
  2. EmitSignal(SignalName.GameOver);

Note: In C#, signal must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.


void free ( )

Deletes the object from memory. Pre-existing references to the object become invalid, and any attempt to access them will result in a run-time error. Checking the references with @GlobalScope.is_instance_valid will return false.


Variant get ( StringName property ) const

Returns the Variant value of the given property. If the property does not exist, this method returns null.

GDScriptC#

  1. var node = Node2D.new()
  2. node.rotation = 1.5
  3. var a = node.get("rotation") # a is 1.5
  1. var node = new Node2D();
  2. node.Rotation = 1.5f;
  3. var a = node.Get("rotation"); // a is 1.5

Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.


String get_class ( ) const

Returns the object’s built-in class name, as a String. See also is_class.

Note: This method ignores class_name declarations. If this object’s script has defined a class_name, the base, built-in class name is returned instead.


Dictionary[] get_incoming_connections ( ) const

Returns an Array of signal connections received by this object. Each connection is represented as a Dictionary that contains three entries:


Variant get_indexed ( NodePath property_path ) const

Gets the object’s property indexed by the given property_path. The path should be a NodePath relative to the current object and can use the colon character (:) to access nested properties.

Examples: "position:x" or "material:next_pass:blend_mode".

GDScriptC#

  1. var node = Node2D.new()
  2. node.position = Vector2(5, -10)
  3. var a = node.get_indexed("position") # a is Vector2(5, -10)
  4. var b = node.get_indexed("position:y") # b is -10
  1. var node = new Node2D();
  2. node.Position = new Vector2(5, -10);
  3. var a = node.GetIndexed("position"); // a is Vector2(5, -10)
  4. var b = node.GetIndexed("position:y"); // b is -10

Note: In C#, property_path must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.

Note: This method does not support actual paths to nodes in the SceneTree, only sub-property paths. In the context of nodes, use Node.get_node_and_resource instead.


int get_instance_id ( ) const

Returns the object’s unique instance ID. This ID can be saved in EncodedObjectAsID, and can be used to retrieve this object instance with @GlobalScope.instance_from_id.


Variant get_meta ( StringName name, Variant default=null ) const

Returns the object’s metadata value for the given entry name. If the entry does not exist, returns default. If default is null, an error is also generated.

Note: A metadata’s name must be a valid identifier as per StringName.is_valid_identifier method.

Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.


StringName[] get_meta_list ( ) const

Returns the object’s metadata entry names as a PackedStringArray.


Dictionary[] get_method_list ( ) const

Returns this object’s methods and their signatures as an Array of dictionaries. Each Dictionary contains the following entries:

  • name is the name of the method, as a String;

  • args is an Array of dictionaries representing the arguments;

  • default_args is the default arguments as an Array of variants;

  • flags is a combination of MethodFlags;

  • id is the method’s internal identifier int;

  • return is the returned value, as a Dictionary;

Note: The dictionaries of args and return are formatted identically to the results of get_property_list, although not all entries are used.


Dictionary[] get_property_list ( ) const

Returns the object’s property list as an Array of dictionaries. Each Dictionary contains the following entries:


Variant get_script ( ) const

Returns the object’s Script instance, or null if no script is attached.


Dictionary[] get_signal_connection_list ( StringName signal ) const

Returns an Array of connections for the given signal name. Each connection is represented as a Dictionary that contains three entries:


Dictionary[] get_signal_list ( ) const

Returns the list of existing signals as an Array of dictionaries.

Note: Due of the implementation, each Dictionary is formatted very similarly to the returned values of get_method_list.


bool has_meta ( StringName name ) const

Returns true if a metadata entry is found with the given name. See also get_meta, set_meta and remove_meta.

Note: A metadata’s name must be a valid identifier as per StringName.is_valid_identifier method.

Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.


bool has_method ( StringName method ) const

Returns true if the given method name exists in the object.

Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.


bool has_signal ( StringName signal ) const

Returns true if the given signal name exists in the object.

Note: In C#, signal must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.


bool has_user_signal ( StringName signal ) const

Returns true if the given user-defined signal name exists. Only signals added with add_user_signal are included.


bool is_blocking_signals ( ) const

Returns true if the object is blocking its signals from being emitted. See set_block_signals.


bool is_class ( String class ) const

Returns true if the object inherits from the given class. See also get_class.

GDScriptC#

  1. var sprite2d = Sprite2D.new()
  2. sprite2d.is_class("Sprite2D") # Returns true
  3. sprite2d.is_class("Node") # Returns true
  4. sprite2d.is_class("Node3D") # Returns false
  1. var sprite2D = new Sprite2D();
  2. sprite2D.IsClass("Sprite2D"); // Returns true
  3. sprite2D.IsClass("Node"); // Returns true
  4. sprite2D.IsClass("Node3D"); // Returns false

Note: This method ignores class_name declarations in the object’s script.


bool is_connected ( StringName signal, Callable callable ) const

Returns true if a connection exists between the given signal name and callable.

Note: In C#, signal must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.


bool is_queued_for_deletion ( ) const

Returns true if the Node.queue_free method was called for the object.


void notification ( int what, bool reversed=false )

Sends the given what notification to all classes inherited by the object, triggering calls to _notification, starting from the highest ancestor (the Object class) and going down to the object’s script.

If reversed is true, the call order is reversed.

GDScriptC#

  1. var player = Node2D.new()
  2. player.set_script(load("res://player.gd"))
  3. player.notification(NOTIFICATION_ENTER_TREE)
  4. # The call order is Object -> Node -> Node2D -> player.gd.
  5. player.notification(NOTIFICATION_ENTER_TREE, true)
  6. # The call order is player.gd -> Node2D -> Node -> Object.
  1. var player = new Node2D();
  2. player.SetScript(GD.Load("res://player.gd"));
  3. player.Notification(NotificationEnterTree);
  4. // The call order is GodotObject -> Node -> Node2D -> player.gd.
  5. player.Notification(NotificationEnterTree, true);
  6. // The call order is player.gd -> Node2D -> Node -> GodotObject.

void notify_property_list_changed ( )

Emits the property_list_changed signal. This is mainly used to refresh the editor, so that the Inspector and editor plugins are properly updated.


bool property_can_revert ( StringName property ) const

Returns true if the given property has a custom default value. Use property_get_revert to get the property‘s default value.

Note: This method is used by the Inspector dock to display a revert icon. The object must implement _property_can_revert to customize the default value. If _property_can_revert is not implemented, this method returns false.


Variant property_get_revert ( StringName property ) const

Returns the custom default value of the given property. Use property_can_revert to check if the property has a custom default value.

Note: This method is used by the Inspector dock to display a revert icon. The object must implement _property_get_revert to customize the default value. If _property_get_revert is not implemented, this method returns null.


void remove_meta ( StringName name )

Removes the given entry name from the object’s metadata. See also has_meta, get_meta and set_meta.

Note: A metadata’s name must be a valid identifier as per StringName.is_valid_identifier method.

Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.


void set ( StringName property, Variant value )

Assigns value to the given property. If the property does not exist or the given value‘s type doesn’t match, nothing happens.

GDScriptC#

  1. var node = Node2D.new()
  2. node.set("global_scale", Vector2(8, 2.5))
  3. print(node.global_scale) # Prints (8, 2.5)
  1. var node = new Node2D();
  2. node.Set("global_scale", new Vector2(8, 2.5));
  3. GD.Print(node.GlobalScale); // Prints Vector2(8, 2.5)

Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.


void set_block_signals ( bool enable )

If set to true, the object becomes unable to emit signals. As such, emit_signal and signal connections will not work, until it is set to false.


void set_deferred ( StringName property, Variant value )

Assigns value to the given property, at the end of the current frame. This is equivalent to calling set through call_deferred.

GDScriptC#

  1. var node = Node2D.new()
  2. add_child(node)
  3. node.rotation = 45.0
  4. node.set_deferred("rotation", 90.0)
  5. print(node.rotation) # Prints 45.0
  6. await get_tree().process_frame
  7. print(node.rotation) # Prints 90.0
  1. var node = new Node2D();
  2. node.Rotation = 45f;
  3. node.SetDeferred("rotation", 90f);
  4. GD.Print(node.Rotation); // Prints 45.0
  5. await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
  6. GD.Print(node.Rotation); // Prints 90.0

Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.


void set_indexed ( NodePath property_path, Variant value )

Assigns a new value to the property identified by the property_path. The path should be a NodePath relative to this object, and can use the colon character (:) to access nested properties.

GDScriptC#

  1. var node = Node2D.new()
  2. node.set_indexed("position", Vector2(42, 0))
  3. node.set_indexed("position:y", -10)
  4. print(node.position) # Prints (42, -10)
  1. var node = new Node2D();
  2. node.SetIndexed("position", new Vector2(42, 0));
  3. node.SetIndexed("position:y", -10);
  4. GD.Print(node.Position); // Prints (42, -10)

Note: In C#, property_path must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.


void set_message_translation ( bool enable )

If set to true, allows the object to translate messages with tr and tr_n. Enabled by default. See also can_translate_messages.


void set_meta ( StringName name, Variant value )

Adds or changes the entry name inside the object’s metadata. The metadata value can be any Variant, although some types cannot be serialized correctly.

If value is null, the entry is removed. This is the equivalent of using remove_meta. See also has_meta and get_meta.

Note: A metadata’s name must be a valid identifier as per StringName.is_valid_identifier method.

Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.


void set_script ( Variant script )

Attaches script to the object, and instantiates it. As a result, the script’s _init is called. A Script is used to extend the object’s functionality.

If a script already exists, its instance is detached, and its property values and state are lost. Built-in property values are still kept.


String to_string ( )

Returns a String representing the object. Defaults to "<ClassName#RID>". Override _to_string to customize the string representation of the object.


String tr ( StringName message, StringName context=”” ) const

Translates a message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation.

If can_translate_messages is false, or no translation is available, this method returns the message without changes. See set_message_translation.

For detailed examples, see Internationalizing games.


String tr_n ( StringName message, StringName plural_message, int n, StringName context=”” ) const

Translates a message or plural_message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation.

If can_translate_messages is false, or no translation is available, this method returns message or plural_message, without changes. See set_message_translation.

The n is the number, or amount, of the message’s subject. It is used by the translation system to fetch the correct plural form for the current language.

For detailed examples, see Localization using gettext.

Note: Negative and float numbers may not properly apply to some countable subjects. It’s recommended handling these cases with tr.