Table of Contents

Class Object

Base class for all other classes in the engine.

Object
Derived

Remarks

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 GodotObject 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 @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 Object.set, Object.get, Object.call, Object.has_method, Object.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:

var node = Node.new()
print("name" in node)         # Prints true
print("get_parent" in node)   # Prints true
print("tree_entered" in node) # Prints true
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 NOTIFICATION_PROCESS. The nodes receive it and may call Node._process to update. To make use of notifications, see Object.notification and Object._notification.

Lastly, every object can also contain metadata (data about data). Object.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 Object.set_script and get_script, respectively.

Note: In a boolean context, an Object will evaluate to false if it is equal to null or it has been freed. Otherwise, an Object will always evaluate to true. See also @GlobalScope.is_instance_valid.

See Also

Fields

NOTIFICATION_POSTINITIALIZE

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

const NOTIFICATION_POSTINITIALIZE = 0

NOTIFICATION_PREDELETE

Notification received when the object is about to be deleted. Can be used like destructors in object-oriented programming languages.

const NOTIFICATION_PREDELETE = 1

NOTIFICATION_EXTENSION_RELOADED

Notification received when the object finishes hot reloading. This notification is only sent for extensions classes and derived.

const NOTIFICATION_EXTENSION_RELOADED = 2

Methods

_get(StringName)

Qualifiers: virtual

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

Combined with Object._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.

func _get(property):
    if property == "fake_property":
        print("Getting my property!")
        return 4

func _get_property_list():
    return [
        { "name": "fake_property", "type": TYPE_INT }

    ]

Variant _get(StringName property)

Parameters

property StringName

_get_property_list

Qualifiers: virtual

Override this method to provide a custom list of additional properties to handle 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.

You can use Object._property_can_revert and Object._property_get_revert to customize the default values of the properties added by this method.

The example below displays a list of numbers shown as words going from ZERO to FIVE, with number_count controlling the size of the list:

@tool
extends Node

@export var number_count = 3:
    set(nc):
        number_count = nc
        numbers.resize(number_count)
        notify_property_list_changed()

var numbers = PackedInt32Array([0, 0, 0])

func _get_property_list():
    var properties = []

    for i in range(number_count):
        properties.append({
            "name": "number_%d" % i,
            "type": TYPE_INT,
            "hint": PROPERTY_HINT_ENUM,
            "hint_string": "ZERO,ONE,TWO,THREE,FOUR,FIVE",
        })

    return properties

func _get(property):
    if property.begins_with("number_"):
        var index = property.get_slice("_", 1).to_int()
        return numbers[index]

func _set(property, value):
    if property.begins_with("number_"):
        var index = property.get_slice("_", 1).to_int()
        numbers[index] = value
        return true
    return false

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

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

Dictionary[] _get_property_list

_init

Qualifiers: virtual

Called when the object's script is instantiated, oftentimes after the object is initialized in memory (through Object.new() in GDScript, or new GodotObject 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 _init

_iter_get(Variant)

Qualifiers: virtual

Returns the current iterable value. iter stores the iteration state, but unlike Object._iter_init and Object._iter_next the state is supposed to be read-only, so there is no Array wrapper.

Variant _iter_get(Variant iter)

Parameters

iter Variant

_iter_init(Array)

Qualifiers: virtual

Initializes the iterator. iter stores the iteration state. Since GDScript does not support passing arguments by reference, a single-element array is used as a wrapper. Returns true so long as the iterator has not reached the end.

Example:

class MyRange:
    var _from
    var _to

    func _init(from, to):
        assert(from <= to)
        _from = from
        _to = to

    func _iter_init(iter):
        iter[0] = _from
        return iter[0] < _to

    func _iter_next(iter):
        iter[0] += 1
        return iter[0] < _to

    func _iter_get(iter):
        return iter

func _ready():
    var my_range = MyRange.new(2, 5)
    for x in my_range:
        print(x) # Prints 2, 3, 4.

Note: Alternatively, you can ignore iter and use the object's state instead, see online docs for an example. Note that in this case you will not be able to reuse the same iterator instance in nested loops. Also, make sure you reset the iterator state in this method if you want to reuse the same instance multiple times.

bool _iter_init(Array iter)

Parameters

iter Array

_iter_next(Array)

Qualifiers: virtual

Moves the iterator to the next iteration. iter stores the iteration state. Since GDScript does not support passing arguments by reference, a single-element array is used as a wrapper. Returns true so long as the iterator has not reached the end.

bool _iter_next(Array iter)

Parameters

iter Array

_notification(int)

Qualifiers: virtual

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

func _notification(what):
    if what == NOTIFICATION_PREDELETE:
        print("Goodbye!")

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.

void _notification(int what)

Parameters

what int

_property_can_revert(StringName)

Qualifiers: virtual

Override this method to customize the given property's revert behavior. Should return true if the property has a custom default value and is revertible in the Inspector dock. Use Object._property_get_revert to specify the property's default value.

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

bool _property_can_revert(StringName property)

Parameters

property StringName

_property_get_revert(StringName)

Qualifiers: 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: Object._property_can_revert must also be overridden for this method to be called.

Variant _property_get_revert(StringName property)

Parameters

property StringName

_set(StringName, Variant)

Qualifiers: virtual

Override this method to customize the behavior of Object.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 Object._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.

var internal_data = {}

func _set(property, value):
    if property == "fake_property":
        # Storing the value in the fake property.
        internal_data["fake_property"] = value
        return true
    return false

func _get_property_list():
    return [
        { "name": "fake_property", "type": TYPE_INT }

    ]

bool _set(StringName property, Variant value)

Parameters

property StringName
value Variant

_to_string

Qualifiers: virtual

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

func _to_string():
    return "Welcome to Godot 4!"

func _init():
    print(self)       # Prints "Welcome to Godot 4!"
    var a = str(self) # a is "Welcome to Godot 4!"

String _to_string

_validate_property(Dictionary)

Qualifiers: virtual

Override this method to customize existing properties. Every property info goes through this method, except properties added with _get_property_list. The dictionary contents is the same as in _get_property_list.

@tool
extends Node

@export var is_number_editable: bool:
    set(value):
        is_number_editable = value
        notify_property_list_changed()
@export var number: int

func _validate_property(property: Dictionary):
    if property.name == "number" and not is_number_editable:
        property.usage |= PROPERTY_USAGE_READ_ONLY

void _validate_property(Dictionary property)

Parameters

property Dictionary

add_user_signal(String, Array)

Adds a user-defined signal named 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 Object.has_user_signal and Object.remove_user_signal.

add_user_signal("hurt", [
    { "name": "damage", "type": TYPE_INT },
    { "name": "source", "type": TYPE_OBJECT }

])

void add_user_signal(String signal, Array arguments)

Parameters

signal String
arguments Array

call(StringName, ...)

Qualifiers: 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.

var node = Node3D.new()
node.call("rotate", Vector3(1.0, 0.0, 0.0), 1.571)

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(StringName method, ...)

Parameters

method StringName

call_deferred(StringName, ...)

Qualifiers: 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. This means you should not call a method deferred from itself (or from a method called by it), as this causes infinite recursion the same way as if you had called the method directly.

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

var node = Node3D.new()
node.call_deferred("rotate", Vector3(1.0, 0.0, 0.0), 1.571)

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 process_frame and physics_frame signals.

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

Variant call_deferred(StringName method, ...)

Parameters

method StringName

callv(StringName, Array)

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

var node = Node3D.new()
node.callv("rotate", [Vector3(1.0, 0.0, 0.0), 1.571])

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 callv(StringName method, Array arg_array)

Parameters

method StringName
arg_array Array

can_translate_messages

Qualifiers: const

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

bool can_translate_messages

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.

void cancel_free

connect(StringName, Callable, int)

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 Object.CONNECT_REFERENCE_COUNTED. To prevent this, use Object.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.

func _ready():
    var button = Button.new()
    # `button_down` here is a Signal variant type, and we thus call the Signal.connect() method, not Object.connect().
    # See discussion below for a more in-depth overview of the API.
    button.button_down.connect(_on_button_down)

    # This assumes that a `Player` class exists, which defines a `hit` signal.
    var player = Player.new()
    # We use Signal.connect() again, and we also use the Callable.bind() method,
    # which returns a new Callable with the parameter binds.
    player.hit.connect(_on_player_hit.bind("sword", 100))

func _on_button_down():
    print("Button down!")

func _on_player_hit(weapon_type, damage):
    print("Hit with weapon %s for %d damage." % [weapon_type, damage])

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

As seen above, the recommended method to connect signals is not Object.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.

func _ready():
    var button = Button.new()
    # Option 1: Object.connect() with an implicit Callable for the defined function.
    button.connect("button_down", _on_button_down)
    # Option 2: Object.connect() with a constructed Callable using a target object and method name.
    button.connect("button_down", Callable(self, "_on_button_down"))
    # Option 3: Signal.connect() with an implicit Callable for the defined function.
    button.button_down.connect(_on_button_down)
    # Option 4: Signal.connect() with a constructed Callable using a target object and method name.
    button.button_down.connect(Callable(self, "_on_button_down"))

func _on_button_down():
    print("Button down!")

While all options have the same outcome (button's 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 Object.emit_signal or Signal.emit, the signal parameters can be also passed. The examples below show the relationship between these signal parameters and bound parameters.

func _ready():
    # This assumes that a `Player` class exists, which defines a `hit` signal.
    var player = Player.new()
    # Using Callable.bind().
    player.hit.connect(_on_player_hit.bind("sword", 100))

    # Parameters added when emitting the signal are passed first.
    player.hit.emit("Dark lord", 5)

# We pass two arguments when emitting (`hit_by`, `level`),
# and bind two more arguments when connecting (`weapon_type`, `damage`).
func _on_player_hit(hit_by, level, weapon_type, damage):
    print("Hit by %s (level %d) with weapon %s for %d damage." % [hit_by, level, weapon_type, damage])

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

Parameters

signal StringName
callable Callable
flags int

disconnect(StringName, Callable)

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

void disconnect(StringName signal, Callable callable)

Parameters

signal StringName
callable Callable

emit_signal(StringName, ...)

Qualifiers: 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 Object.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.

emit_signal("hit", "sword", 100)
emit_signal("game_over")

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.

int emit_signal(StringName signal, ...)

Parameters

signal StringName

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.

void free

get(StringName)

Qualifiers: const

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

var node = Node2D.new()
node.rotation = 1.5
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.

Variant get(StringName property)

Parameters

property StringName

get_class

Qualifiers: const

Returns the object's built-in class name, as a String. See also Object.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.

String get_class

get_incoming_connections

Qualifiers: const

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

  • signal is a reference to the Signal;

  • callable is a reference to the Callable;

  • flags is a combination of ConnectFlags.

Dictionary[] get_incoming_connections

get_indexed(NodePath)

Qualifiers: 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".

var node = Node2D.new()
node.position = Vector2(5, -10)
var a = node.get_indexed("position")   # a is Vector2(5, -10)
var b = node.get_indexed("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.

Variant get_indexed(NodePath property_path)

Parameters

property_path NodePath

get_instance_id

Qualifiers: 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.

Note: This ID is only useful during the current session. It won't correspond to a similar object if the ID is sent over a network, or loaded from a file at a later time.

int get_instance_id

get_meta(StringName, Variant)

Qualifiers: 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 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.

Variant get_meta(StringName name, Variant default)

Parameters

name StringName
default Variant

get_meta_list

Qualifiers: const

Returns the object's metadata entry names as an Array of StringNames.

StringName[] get_meta_list

get_method_argument_count(StringName)

Qualifiers: const

Returns the number of arguments of the given method by name.

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.

int get_method_argument_count(StringName method)

Parameters

method StringName

get_method_list

Qualifiers: 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_method_list

get_property_list

Qualifiers: const

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

  • name is the property's name, as a String;

  • class_name is an empty StringName, unless the property is @GlobalScope.TYPE_OBJECT and it inherits from a class;

  • type is the property's type, as an int (see Variant.Type);

  • hint is how the property is meant to be edited (see PropertyHint);

  • hint_string depends on the hint (see PropertyHint);

  • usage is a combination of PropertyUsageFlags.

Note: In GDScript, all class members are treated as properties. In C# and GDExtension, it may be necessary to explicitly mark class members as Godot properties using decorators or attributes.

Dictionary[] get_property_list

get_script

Qualifiers: const

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

Variant get_script

get_signal_connection_list(StringName)

Qualifiers: const

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

  • signal is a reference to the Signal;

  • callable is a reference to the connected Callable;

  • flags is a combination of ConnectFlags.

Dictionary[] get_signal_connection_list(StringName signal)

Parameters

signal StringName

get_signal_list

Qualifiers: 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.

Dictionary[] get_signal_list

get_translation_domain

Qualifiers: const

Returns the name of the translation domain used by Object.tr and Object.tr_n. See also TranslationServer.

StringName get_translation_domain

has_connections(StringName)

Qualifiers: const

Returns true if any connection exists on the given signal name.

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_connections(StringName signal)

Parameters

signal StringName

has_meta(StringName)

Qualifiers: const

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

Note: A metadata's name must be a valid identifier as per 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_meta(StringName name)

Parameters

name StringName

has_method(StringName)

Qualifiers: 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_method(StringName method)

Parameters

method StringName

has_signal(StringName)

Qualifiers: 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 signals. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.

bool has_signal(StringName signal)

Parameters

signal StringName

has_user_signal(StringName)

Qualifiers: const

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

bool has_user_signal(StringName signal)

Parameters

signal StringName

is_blocking_signals

Qualifiers: const

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

bool is_blocking_signals

is_class(String)

Qualifiers: const

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

var sprite2d = Sprite2D.new()
sprite2d.is_class("Sprite2D") # Returns true
sprite2d.is_class("Node")     # Returns true
sprite2d.is_class("Node3D")   # Returns false

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

bool is_class(String class)

Parameters

class String

is_connected(StringName, Callable)

Qualifiers: 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 signals. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.

bool is_connected(StringName signal, Callable callable)

Parameters

signal StringName
callable Callable

is_queued_for_deletion

Qualifiers: const

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

bool is_queued_for_deletion

notification(int, bool)

Sends the given what notification to all classes inherited by the object, triggering calls to Object._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.

var player = Node2D.new()
player.set_script(load("res://player.gd"))

player.notification(NOTIFICATION_ENTER_TREE)
# The call order is Object -> Node -> Node2D -> player.gd.

player.notification(NOTIFICATION_ENTER_TREE, true)
# The call order is player.gd -> Node2D -> Node -> Object.

void notification(int what, bool reversed)

Parameters

what int
reversed bool

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.

void notify_property_list_changed

property_can_revert(StringName)

Qualifiers: const

Returns true if the given property has a custom default value. Use Object.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 Object._property_can_revert to customize the default value. If Object._property_can_revert is not implemented, this method returns false.

bool property_can_revert(StringName property)

Parameters

property StringName

property_get_revert(StringName)

Qualifiers: const

Returns the custom default value of the given property. Use Object.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 Object._property_get_revert to customize the default value. If Object._property_get_revert is not implemented, this method returns null.

Variant property_get_revert(StringName property)

Parameters

property StringName

remove_meta(StringName)

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

Note: A metadata's name must be a valid identifier as per 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 remove_meta(StringName name)

Parameters

name StringName

remove_user_signal(StringName)

Removes the given user signal signal from the object. See also Object.add_user_signal and Object.has_user_signal.

void remove_user_signal(StringName signal)

Parameters

signal StringName

set(StringName, Variant)

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

var node = Node2D.new()
node.set("global_scale", Vector2(8, 2.5))
print(node.global_scale) # Prints (8.0, 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(StringName property, Variant value)

Parameters

property StringName
value Variant

set_block_signals(bool)

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

void set_block_signals(bool enable)

Parameters

enable bool

set_deferred(StringName, Variant)

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

var node = Node2D.new()
add_child(node)

node.rotation = 1.5
node.set_deferred("rotation", 3.0)
print(node.rotation) # Prints 1.5

await get_tree().process_frame
print(node.rotation) # Prints 3.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_deferred(StringName property, Variant value)

Parameters

property StringName
value Variant

set_indexed(NodePath, Variant)

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.

var node = Node2D.new()
node.set_indexed("position", Vector2(42, 0))
node.set_indexed("position:y", -10)
print(node.position) # Prints (42.0, -10.0)

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_indexed(NodePath property_path, Variant value)

Parameters

property_path NodePath
value Variant

set_message_translation(bool)

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

void set_message_translation(bool enable)

Parameters

enable bool

set_meta(StringName, Variant)

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 Object.remove_meta. See also Object.has_meta and Object.get_meta.

Note: A metadata's name must be a valid identifier as per 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_meta(StringName name, Variant value)

Parameters

name StringName
value Variant

set_script(Variant)

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.

void set_script(Variant script)

Parameters

script Variant

set_translation_domain(StringName)

Sets the name of the translation domain used by Object.tr and Object.tr_n. See also TranslationServer.

void set_translation_domain(StringName domain)

Parameters

domain StringName

to_string

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

String to_string

tr(StringName, StringName)

Qualifiers: const

Translates a message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation. Note that most Control nodes automatically translate their strings, so this method is mostly useful for formatted strings or custom drawn text.

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

For detailed examples, see Internationalizing games.

Note: This method can't be used without an Object instance, as it requires the can_translate_messages method. To translate strings in a static context, use TranslationServer.translate.

String tr(StringName message, StringName context)

Parameters

message StringName
context StringName

tr_n(StringName, StringName, int, StringName)

Qualifiers: 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 Object.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 to handle these cases with Object.tr.

Note: This method can't be used without an Object instance, as it requires the can_translate_messages method. To translate strings in a static context, use TranslationServer.translate_plural.

String tr_n(StringName message, StringName plural_message, int n, StringName context)

Parameters

message StringName
plural_message StringName
n int
context StringName

Events

property_list_changed

Emitted when notify_property_list_changed is called.

signal property_list_changed

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 Object.CONNECT_DEFERRED.

signal script_changed