:github_url: hide .. Generated automatically by doc/tools/makerst.py in Godot's source tree. .. DO NOT EDIT THIS FILE, but the Object.xml source instead. .. The source is found in doc/classes or modules//doc_classes. .. _class_Object: Object ====== **Inherited By:** :ref:`ARVRPositionalTracker`, :ref:`ARVRServer`, :ref:`AudioServer`, :ref:`ClassDB`, :ref:`EditorFileSystemDirectory`, :ref:`EditorSelection`, :ref:`Engine`, :ref:`Geometry`, :ref:`GodotSharp`, :ref:`IP`, :ref:`Input`, :ref:`InputMap`, :ref:`JSON`, :ref:`JavaScript`, :ref:`MainLoop`, :ref:`Node`, :ref:`OS`, :ref:`Performance`, :ref:`Physics2DDirectBodyState`, :ref:`Physics2DDirectSpaceState`, :ref:`Physics2DServer`, :ref:`PhysicsDirectBodyState`, :ref:`PhysicsDirectSpaceState`, :ref:`PhysicsServer`, :ref:`ProjectSettings`, :ref:`Reference`, :ref:`ResourceLoader`, :ref:`ResourceSaver`, :ref:`TranslationServer`, :ref:`TreeItem`, :ref:`UndoRedo`, :ref:`VisualScriptEditor`, :ref:`VisualServer` **Category:** Core Brief Description ----------------- Base class for all non built-in types. Methods ------- +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`_get` **(** :ref:`String` property **)** virtual | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Array` | :ref:`_get_property_list` **(** **)** virtual | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`_init` **(** **)** virtual | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`_notification` **(** :ref:`int` what **)** virtual | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`_set` **(** :ref:`String` property, :ref:`Variant` value **)** virtual | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_user_signal` **(** :ref:`String` signal, :ref:`Array` arguments=[ ] **)** | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`call` **(** :ref:`String` method, ... **)** vararg | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`call_deferred` **(** :ref:`String` method, ... **)** vararg | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`callv` **(** :ref:`String` method, :ref:`Array` arg_array **)** | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`can_translate_messages` **(** **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`connect` **(** :ref:`String` signal, :ref:`Object` target, :ref:`String` method, :ref:`Array` binds=[ ], :ref:`int` flags=0 **)** | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`disconnect` **(** :ref:`String` signal, :ref:`Object` target, :ref:`String` method **)** | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`emit_signal` **(** :ref:`String` signal, ... **)** vararg | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`free` **(** **)** | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`get` **(** :ref:`String` property **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`String` | :ref:`get_class` **(** **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Array` | :ref:`get_incoming_connections` **(** **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`get_indexed` **(** :ref:`NodePath` property **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_instance_id` **(** **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`get_meta` **(** :ref:`String` name **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PoolStringArray` | :ref:`get_meta_list` **(** **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Array` | :ref:`get_method_list` **(** **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Array` | :ref:`get_property_list` **(** **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Reference` | :ref:`get_script` **(** **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Array` | :ref:`get_signal_connection_list` **(** :ref:`String` signal **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Array` | :ref:`get_signal_list` **(** **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`has_meta` **(** :ref:`String` name **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`has_method` **(** :ref:`String` method **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`has_user_signal` **(** :ref:`String` signal **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_blocking_signals` **(** **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_class` **(** :ref:`String` class **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_connected` **(** :ref:`String` signal, :ref:`Object` target, :ref:`String` method **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_queued_for_deletion` **(** **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`notification` **(** :ref:`int` what, :ref:`bool` reversed=false **)** | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`property_list_changed_notify` **(** **)** | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set` **(** :ref:`String` property, :ref:`Variant` value **)** | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_block_signals` **(** :ref:`bool` enable **)** | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_deferred` **(** :ref:`String` property, :ref:`Variant` value **)** | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_indexed` **(** :ref:`NodePath` property, :ref:`Variant` value **)** | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_message_translation` **(** :ref:`bool` enable **)** | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_meta` **(** :ref:`String` name, :ref:`Variant` value **)** | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_script` **(** :ref:`Reference` script **)** | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`String` | :ref:`tr` **(** :ref:`String` message **)** const | +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Signals ------- .. _class_Object_signal_script_changed: - **script_changed** **(** **)** Emitted whenever the object's script is changed. Enumerations ------------ .. _enum_Object_ConnectFlags: .. _class_Object_constant_CONNECT_DEFERRED: .. _class_Object_constant_CONNECT_PERSIST: .. _class_Object_constant_CONNECT_ONESHOT: .. _class_Object_constant_CONNECT_REFERENCE_COUNTED: enum **ConnectFlags**: - **CONNECT_DEFERRED** = **1** --- Connect a signal in deferred mode. This way, signal emissions are stored in a queue, then set on idle time. - **CONNECT_PERSIST** = **2** --- Persisting connections are saved when the object is serialized to file. - **CONNECT_ONESHOT** = **4** --- One shot connections disconnect themselves after emission. - **CONNECT_REFERENCE_COUNTED** = **8** --- Connect a signal as reference counted. This means that a given signal can be connected several times to the same target, and will only be fully disconnected once no references are left. Constants --------- .. _class_Object_constant_NOTIFICATION_POSTINITIALIZE: .. _class_Object_constant_NOTIFICATION_PREDELETE: - **NOTIFICATION_POSTINITIALIZE** = **0** --- Called right when the object is initialized. Not available in script. - **NOTIFICATION_PREDELETE** = **1** --- Called before the object is about to be deleted. Description ----------- Every class which is not a built-in type inherits from this class. You can construct Objects from scripting languages, using ``Object.new()`` in GDScript, ``new Object`` in C#, or the "Construct Object" node in VisualScript. Objects do not manage memory. If a class inherits from Object, you will have to delete instances of it manually. To do so, call the :ref:`free` method from your script or delete the instance from C++. Some classes that extend Object add memory management. This is the case of :ref:`Reference`, which counts references and deletes itself automatically when no longer referenced. :ref:`Node`, another fundamental type, deletes all its children when freed from memory. Objects export properties, which are mainly useful for storage and editing, but not really so much in programming. Properties are exported in :ref:`_get_property_list` and handled in :ref:`_get` and :ref:`_set`. However, scripting languages and C++ have simpler means to export them. Objects also receive notifications. Notifications are a simple way to notify the object about different events, so they can all be handled together. See :ref:`_notification`. Method Descriptions ------------------- .. _class_Object_method__get: - :ref:`Variant` **_get** **(** :ref:`String` property **)** virtual Virtual method which can be overridden to customize the return value of :ref:`get`. Returns the given property. Returns ``null`` if the ``property`` does not exist. ---- .. _class_Object_method__get_property_list: - :ref:`Array` **_get_property_list** **(** **)** virtual Virtual method which can be overridden to customize the return value of :ref:`get_property_list`. Returns the object's property list as an :ref:`Array` of dictionaries. Each property's :ref:`Dictionary` must contain at least ``name: String`` and ``type: int`` (see :ref:`Variant.Type`) entries. Optionally, it can also include ``hint: int`` (see :ref:`PropertyHint`), ``hint_string: String``, and ``usage: int`` (see :ref:`PropertyUsageFlags`). ---- .. _class_Object_method__init: - void **_init** **(** **)** virtual Called when the object is initialized. ---- .. _class_Object_method__notification: - void **_notification** **(** :ref:`int` what **)** virtual Called whenever the object receives a notification, which is identified in ``what`` by a constant. The base :ref:`Object` has two constants :ref:`NOTIFICATION_POSTINITIALIZE` and :ref:`NOTIFICATION_PREDELETE`, but subclasses such as :ref:`Node` define a lot more notifications which are also received by this method. ---- .. _class_Object_method__set: - :ref:`bool` **_set** **(** :ref:`String` property, :ref:`Variant` value **)** virtual Virtual method which can be overridden to customize the return value of :ref:`set`. Sets a property. Returns ``true`` if the ``property`` exists. ---- .. _class_Object_method_add_user_signal: - void **add_user_signal** **(** :ref:`String` signal, :ref:`Array` arguments=[ ] **)** Adds a user-defined ``signal``. Arguments are optional, but can be added as an :ref:`Array` of dictionaries, each containing ``name: String`` and ``type: int`` (see :ref:`Variant.Type`) entries. ---- .. _class_Object_method_call: - :ref:`Variant` **call** **(** :ref:`String` method, ... **)** vararg Calls the ``method`` on the object and returns the result. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example: :: call("set", "position", Vector2(42.0, 0.0)) ---- .. _class_Object_method_call_deferred: - :ref:`Variant` **call_deferred** **(** :ref:`String` method, ... **)** vararg Calls the ``method`` on the object during idle time and returns the result. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example: :: call_deferred("set", "position", Vector2(42.0, 0.0)) ---- .. _class_Object_method_callv: - :ref:`Variant` **callv** **(** :ref:`String` method, :ref:`Array` arg_array **)** Calls the ``method`` on the object and returns the result. Contrarily to :ref:`call`, this method does not support a variable number of arguments but expected all parameters passed via a single :ref:`Array`. :: callv("set", [ "position", Vector2(42.0, 0.0) ]) ---- .. _class_Object_method_can_translate_messages: - :ref:`bool` **can_translate_messages** **(** **)** const Returns ``true`` if the object can translate strings. See :ref:`set_message_translation` and :ref:`tr`. ---- .. _class_Object_method_connect: - :ref:`Error` **connect** **(** :ref:`String` signal, :ref:`Object` target, :ref:`String` method, :ref:`Array` binds=[ ], :ref:`int` flags=0 **)** Connects a ``signal`` to a ``method`` on a ``target`` object. Pass optional ``binds`` to the call as an :ref:`Array` of parameters. Use ``flags`` to set deferred or one shot connections. See :ref:`ConnectFlags` constants. A ``signal`` can only be connected once to a ``method``. It will throw an error if already connected, unless the signal was connected with :ref:`CONNECT_REFERENCE_COUNTED`. To avoid this, first, use :ref:`is_connected` to check for existing connections. If the ``target`` is destroyed in the game's lifecycle, the connection will be lost. Examples: :: connect("pressed", self, "_on_Button_pressed") # BaseButton signal connect("text_entered", self, "_on_LineEdit_text_entered") # LineEdit signal connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # User-defined signal ---- .. _class_Object_method_disconnect: - void **disconnect** **(** :ref:`String` signal, :ref:`Object` target, :ref:`String` method **)** Disconnects a ``signal`` from a ``method`` on the given ``target``. If you try to disconnect a connection that does not exist, the method will throw an error. Use :ref:`is_connected` to ensure that the connection exists. ---- .. _class_Object_method_emit_signal: - :ref:`Variant` **emit_signal** **(** :ref:`String` signal, ... **)** vararg Emits the given ``signal``. The signal must exist, so it should be a built-in signal of this class or one of its parent classes, or a user-defined signal. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example: :: emit_signal("hit", weapon_type, damage) emit_signal("game_over") ---- .. _class_Object_method_free: - void **free** **(** **)** Deletes the object from memory. Any pre-existing reference to the freed object will now return ``null``. ---- .. _class_Object_method_get: - :ref:`Variant` **get** **(** :ref:`String` property **)** const Returns the :ref:`Variant` value of the given ``property``. ---- .. _class_Object_method_get_class: - :ref:`String` **get_class** **(** **)** const Returns the object's class as a :ref:`String`. ---- .. _class_Object_method_get_incoming_connections: - :ref:`Array` **get_incoming_connections** **(** **)** const Returns an :ref:`Array` of dictionaries with information about signals that are connected to the object. Each :ref:`Dictionary` contains three String entries: - ``source`` is a reference to the signal emitter. - ``signal_name`` is the name of the connected signal. - ``method_name`` is the name of the method to which the signal is connected. ---- .. _class_Object_method_get_indexed: - :ref:`Variant` **get_indexed** **(** :ref:`NodePath` property **)** const Get the object's property indexed by the given :ref:`NodePath`. The node path should be relative to the current object and can use the colon character (``:``) to access nested properties. Examples: ``"position:x"`` or ``"material:next_pass:blend_mode"``. ---- .. _class_Object_method_get_instance_id: - :ref:`int` **get_instance_id** **(** **)** const Returns the object's unique instance ID. This ID can be saved in :ref:`EncodedObjectAsID`, and can be used to retrieve the object instance with :ref:`@GDScript.instance_from_id`. ---- .. _class_Object_method_get_meta: - :ref:`Variant` **get_meta** **(** :ref:`String` name **)** const Returns the object's metadata entry for the given ``name``. ---- .. _class_Object_method_get_meta_list: - :ref:`PoolStringArray` **get_meta_list** **(** **)** const Returns the object's metadata as a :ref:`PoolStringArray`. ---- .. _class_Object_method_get_method_list: - :ref:`Array` **get_method_list** **(** **)** const Returns the object's methods and their signatures as an :ref:`Array`. ---- .. _class_Object_method_get_property_list: - :ref:`Array` **get_property_list** **(** **)** const Returns the object's property list as an :ref:`Array` of dictionaries. Each property's :ref:`Dictionary` contain at least ``name: String`` and ``type: int`` (see :ref:`Variant.Type`) entries. Optionally, it can also include ``hint: int`` (see :ref:`PropertyHint`), ``hint_string: String``, and ``usage: int`` (see :ref:`PropertyUsageFlags`). ---- .. _class_Object_method_get_script: - :ref:`Reference` **get_script** **(** **)** const Returns the object's :ref:`Script` instance, or ``null`` if none is assigned. ---- .. _class_Object_method_get_signal_connection_list: - :ref:`Array` **get_signal_connection_list** **(** :ref:`String` signal **)** const Returns an :ref:`Array` of connections for the given ``signal``. ---- .. _class_Object_method_get_signal_list: - :ref:`Array` **get_signal_list** **(** **)** const Returns the list of signals as an :ref:`Array` of dictionaries. ---- .. _class_Object_method_has_meta: - :ref:`bool` **has_meta** **(** :ref:`String` name **)** const Returns ``true`` if a metadata entry is found with the given ``name``. ---- .. _class_Object_method_has_method: - :ref:`bool` **has_method** **(** :ref:`String` method **)** const Returns ``true`` if the object contains the given ``method``. ---- .. _class_Object_method_has_user_signal: - :ref:`bool` **has_user_signal** **(** :ref:`String` signal **)** const Returns ``true`` if the given user-defined ``signal`` exists. ---- .. _class_Object_method_is_blocking_signals: - :ref:`bool` **is_blocking_signals** **(** **)** const Returns ``true`` if signal emission blocking is enabled. ---- .. _class_Object_method_is_class: - :ref:`bool` **is_class** **(** :ref:`String` class **)** const Returns ``true`` if the object inherits from the given ``class``. ---- .. _class_Object_method_is_connected: - :ref:`bool` **is_connected** **(** :ref:`String` signal, :ref:`Object` target, :ref:`String` method **)** const Returns ``true`` if a connection exists for a given ``signal``, ``target``, and ``method``. ---- .. _class_Object_method_is_queued_for_deletion: - :ref:`bool` **is_queued_for_deletion** **(** **)** const Returns ``true`` if the :ref:`Node.queue_free` method was called for the object. ---- .. _class_Object_method_notification: - void **notification** **(** :ref:`int` what, :ref:`bool` reversed=false **)** Send a given notification to the object, which will also trigger a call to the :ref:`_notification` method of all classes that the object inherits from. If ``reversed`` is ``true``, :ref:`_notification` is called first on the object's own class, and then up to its successive parent classes. If ``reversed`` is ``false``, :ref:`_notification` is called first on the highest ancestor (:ref:`Object` itself), and then down to its successive inheriting classes. ---- .. _class_Object_method_property_list_changed_notify: - void **property_list_changed_notify** **(** **)** Notify the editor that the property list has changed, so that editor plugins can take the new values into account. Does nothing on export builds. ---- .. _class_Object_method_set: - void **set** **(** :ref:`String` property, :ref:`Variant` value **)** Assigns a new value to the given property. If the ``property`` does not exist, nothing will happen. ---- .. _class_Object_method_set_block_signals: - void **set_block_signals** **(** :ref:`bool` enable **)** If set to ``true``, signal emission is blocked. ---- .. _class_Object_method_set_deferred: - void **set_deferred** **(** :ref:`String` property, :ref:`Variant` value **)** Assigns a new value to the given property, after the current frame's physics step. This is equivalent to calling :ref:`set` via :ref:`call_deferred`, i.e. ``call_deferred("set", property, value)``. ---- .. _class_Object_method_set_indexed: - void **set_indexed** **(** :ref:`NodePath` property, :ref:`Variant` value **)** Assigns a new value to the property identified by the :ref:`NodePath`. The node path should be relative to the current object and can use the colon character (``:``) to access nested properties. Example: :: set_indexed("position", Vector2(42, 0)) set_indexed("position:y", -10) print(position) # (42, -10) ---- .. _class_Object_method_set_message_translation: - void **set_message_translation** **(** :ref:`bool` enable **)** Defines whether the object can translate strings (with calls to :ref:`tr`). Default is ``true``. ---- .. _class_Object_method_set_meta: - void **set_meta** **(** :ref:`String` name, :ref:`Variant` value **)** Adds or changes a given entry in the object's metadata. Metadata are serialized, and can take any :ref:`Variant` value. ---- .. _class_Object_method_set_script: - void **set_script** **(** :ref:`Reference` script **)** Assigns a script to the object. Each object can have a single script assigned to it, which are used to extend its functionality. ---- .. _class_Object_method_tr: - :ref:`String` **tr** **(** :ref:`String` message **)** const Translates a message using translation catalogs configured in the Project Settings. Only works if message translation is enabled (which it is by default), otherwise it returns the ``message`` unchanged. See :ref:`set_message_translation`.