class_object.rst 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Object.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Object:
  6. Object
  7. ======
  8. **Inherited By:** :ref:`ARVRPositionalTracker<class_ARVRPositionalTracker>`, :ref:`ARVRServer<class_ARVRServer>`, :ref:`AudioServer<class_AudioServer>`, :ref:`CameraServer<class_CameraServer>`, :ref:`ClassDB<class_ClassDB>`, :ref:`EditorFileSystemDirectory<class_EditorFileSystemDirectory>`, :ref:`EditorNavigationMeshGenerator<class_EditorNavigationMeshGenerator>`, :ref:`EditorSelection<class_EditorSelection>`, :ref:`EditorVCSInterface<class_EditorVCSInterface>`, :ref:`Engine<class_Engine>`, :ref:`Geometry<class_Geometry>`, :ref:`GodotSharp<class_GodotSharp>`, :ref:`IP<class_IP>`, :ref:`Input<class_Input>`, :ref:`InputMap<class_InputMap>`, :ref:`JSON<class_JSON>`, :ref:`JSONRPC<class_JSONRPC>`, :ref:`JavaClassWrapper<class_JavaClassWrapper>`, :ref:`JavaScript<class_JavaScript>`, :ref:`MainLoop<class_MainLoop>`, :ref:`Marshalls<class_Marshalls>`, :ref:`Node<class_Node>`, :ref:`OS<class_OS>`, :ref:`Performance<class_Performance>`, :ref:`Physics2DDirectBodyState<class_Physics2DDirectBodyState>`, :ref:`Physics2DDirectSpaceState<class_Physics2DDirectSpaceState>`, :ref:`Physics2DServer<class_Physics2DServer>`, :ref:`PhysicsDirectBodyState<class_PhysicsDirectBodyState>`, :ref:`PhysicsDirectSpaceState<class_PhysicsDirectSpaceState>`, :ref:`PhysicsServer<class_PhysicsServer>`, :ref:`ProjectSettings<class_ProjectSettings>`, :ref:`Reference<class_Reference>`, :ref:`ResourceLoader<class_ResourceLoader>`, :ref:`ResourceSaver<class_ResourceSaver>`, :ref:`TranslationServer<class_TranslationServer>`, :ref:`TreeItem<class_TreeItem>`, :ref:`UndoRedo<class_UndoRedo>`, :ref:`VisualScriptEditor<class_VisualScriptEditor>`, :ref:`VisualServer<class_VisualServer>`
  9. Base class for all non built-in types.
  10. Description
  11. -----------
  12. Every class which is not a built-in type inherits from this class.
  13. You can construct Objects from scripting languages, using ``Object.new()`` in GDScript, ``new Object`` in C#, or the "Construct Object" node in VisualScript.
  14. 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<class_Object_method_free>` method from your script or delete the instance from C++.
  15. Some classes that extend Object add memory management. This is the case of :ref:`Reference<class_Reference>`, which counts references and deletes itself automatically when no longer referenced. :ref:`Node<class_Node>`, another fundamental type, deletes all its children when freed from memory.
  16. 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<class_Object_method__get_property_list>` and handled in :ref:`_get<class_Object_method__get>` and :ref:`_set<class_Object_method__set>`. However, scripting languages and C++ have simpler means to export them.
  17. Property membership can be tested directly in GDScript using ``in``:
  18. ::
  19. var n = Node2D.new()
  20. print("position" in n) # Prints "True".
  21. print("other_property" in n) # Prints "False".
  22. 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<class_Object_method__notification>`.
  23. Methods
  24. -------
  25. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`Variant<class_Variant>` | :ref:`_get<class_Object_method__get>` **(** :ref:`String<class_String>` property **)** virtual |
  27. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`Array<class_Array>` | :ref:`_get_property_list<class_Object_method__get_property_list>` **(** **)** virtual |
  29. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | void | :ref:`_init<class_Object_method__init>` **(** **)** virtual |
  31. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | void | :ref:`_notification<class_Object_method__notification>` **(** :ref:`int<class_int>` what **)** virtual |
  33. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`bool<class_bool>` | :ref:`_set<class_Object_method__set>` **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** virtual |
  35. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`String<class_String>` | :ref:`_to_string<class_Object_method__to_string>` **(** **)** virtual |
  37. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | void | :ref:`add_user_signal<class_Object_method_add_user_signal>` **(** :ref:`String<class_String>` signal, :ref:`Array<class_Array>` arguments=[ ] **)** |
  39. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Variant<class_Variant>` | :ref:`call<class_Object_method_call>` **(** :ref:`String<class_String>` method, ... **)** vararg |
  41. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`call_deferred<class_Object_method_call_deferred>` **(** :ref:`String<class_String>` method, ... **)** vararg |
  43. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`Variant<class_Variant>` | :ref:`callv<class_Object_method_callv>` **(** :ref:`String<class_String>` method, :ref:`Array<class_Array>` arg_array **)** |
  45. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`bool<class_bool>` | :ref:`can_translate_messages<class_Object_method_can_translate_messages>` **(** **)** const |
  47. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`connect<class_Object_method_connect>` **(** :ref:`String<class_String>` signal, :ref:`Object<class_Object>` target, :ref:`String<class_String>` method, :ref:`Array<class_Array>` binds=[ ], :ref:`int<class_int>` flags=0 **)** |
  49. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`disconnect<class_Object_method_disconnect>` **(** :ref:`String<class_String>` signal, :ref:`Object<class_Object>` target, :ref:`String<class_String>` method **)** |
  51. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | void | :ref:`emit_signal<class_Object_method_emit_signal>` **(** :ref:`String<class_String>` signal, ... **)** vararg |
  53. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | void | :ref:`free<class_Object_method_free>` **(** **)** |
  55. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Variant<class_Variant>` | :ref:`get<class_Object_method_get>` **(** :ref:`String<class_String>` property **)** const |
  57. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`String<class_String>` | :ref:`get_class<class_Object_method_get_class>` **(** **)** const |
  59. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Array<class_Array>` | :ref:`get_incoming_connections<class_Object_method_get_incoming_connections>` **(** **)** const |
  61. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Variant<class_Variant>` | :ref:`get_indexed<class_Object_method_get_indexed>` **(** :ref:`NodePath<class_NodePath>` property **)** const |
  63. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`int<class_int>` | :ref:`get_instance_id<class_Object_method_get_instance_id>` **(** **)** const |
  65. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`Variant<class_Variant>` | :ref:`get_meta<class_Object_method_get_meta>` **(** :ref:`String<class_String>` name **)** const |
  67. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`PoolStringArray<class_PoolStringArray>` | :ref:`get_meta_list<class_Object_method_get_meta_list>` **(** **)** const |
  69. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Array<class_Array>` | :ref:`get_method_list<class_Object_method_get_method_list>` **(** **)** const |
  71. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`Array<class_Array>` | :ref:`get_property_list<class_Object_method_get_property_list>` **(** **)** const |
  73. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`Reference<class_Reference>` | :ref:`get_script<class_Object_method_get_script>` **(** **)** const |
  75. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`Array<class_Array>` | :ref:`get_signal_connection_list<class_Object_method_get_signal_connection_list>` **(** :ref:`String<class_String>` signal **)** const |
  77. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`Array<class_Array>` | :ref:`get_signal_list<class_Object_method_get_signal_list>` **(** **)** const |
  79. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`bool<class_bool>` | :ref:`has_meta<class_Object_method_has_meta>` **(** :ref:`String<class_String>` name **)** const |
  81. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`bool<class_bool>` | :ref:`has_method<class_Object_method_has_method>` **(** :ref:`String<class_String>` method **)** const |
  83. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`bool<class_bool>` | :ref:`has_user_signal<class_Object_method_has_user_signal>` **(** :ref:`String<class_String>` signal **)** const |
  85. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`bool<class_bool>` | :ref:`is_blocking_signals<class_Object_method_is_blocking_signals>` **(** **)** const |
  87. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`bool<class_bool>` | :ref:`is_class<class_Object_method_is_class>` **(** :ref:`String<class_String>` class **)** const |
  89. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`bool<class_bool>` | :ref:`is_connected<class_Object_method_is_connected>` **(** :ref:`String<class_String>` signal, :ref:`Object<class_Object>` target, :ref:`String<class_String>` method **)** const |
  91. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`bool<class_bool>` | :ref:`is_queued_for_deletion<class_Object_method_is_queued_for_deletion>` **(** **)** const |
  93. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | void | :ref:`notification<class_Object_method_notification>` **(** :ref:`int<class_int>` what, :ref:`bool<class_bool>` reversed=false **)** |
  95. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | void | :ref:`property_list_changed_notify<class_Object_method_property_list_changed_notify>` **(** **)** |
  97. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | void | :ref:`remove_meta<class_Object_method_remove_meta>` **(** :ref:`String<class_String>` name **)** |
  99. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | void | :ref:`set<class_Object_method_set>` **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** |
  101. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | void | :ref:`set_block_signals<class_Object_method_set_block_signals>` **(** :ref:`bool<class_bool>` enable **)** |
  103. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | void | :ref:`set_deferred<class_Object_method_set_deferred>` **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** |
  105. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | void | :ref:`set_indexed<class_Object_method_set_indexed>` **(** :ref:`NodePath<class_NodePath>` property, :ref:`Variant<class_Variant>` value **)** |
  107. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | void | :ref:`set_message_translation<class_Object_method_set_message_translation>` **(** :ref:`bool<class_bool>` enable **)** |
  109. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | void | :ref:`set_meta<class_Object_method_set_meta>` **(** :ref:`String<class_String>` name, :ref:`Variant<class_Variant>` value **)** |
  111. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | void | :ref:`set_script<class_Object_method_set_script>` **(** :ref:`Reference<class_Reference>` script **)** |
  113. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | :ref:`String<class_String>` | :ref:`to_string<class_Object_method_to_string>` **(** **)** |
  115. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | :ref:`String<class_String>` | :ref:`tr<class_Object_method_tr>` **(** :ref:`String<class_String>` message **)** const |
  117. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  118. Signals
  119. -------
  120. .. _class_Object_signal_script_changed:
  121. - **script_changed** **(** **)**
  122. Emitted whenever the object's script is changed.
  123. Enumerations
  124. ------------
  125. .. _enum_Object_ConnectFlags:
  126. .. _class_Object_constant_CONNECT_DEFERRED:
  127. .. _class_Object_constant_CONNECT_PERSIST:
  128. .. _class_Object_constant_CONNECT_ONESHOT:
  129. .. _class_Object_constant_CONNECT_REFERENCE_COUNTED:
  130. enum **ConnectFlags**:
  131. - **CONNECT_DEFERRED** = **1** --- Connects a signal in deferred mode. This way, signal emissions are stored in a queue, then set on idle time.
  132. - **CONNECT_PERSIST** = **2** --- Persisting connections are saved when the object is serialized to file.
  133. - **CONNECT_ONESHOT** = **4** --- One-shot connections disconnect themselves after emission.
  134. - **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.
  135. Constants
  136. ---------
  137. .. _class_Object_constant_NOTIFICATION_POSTINITIALIZE:
  138. .. _class_Object_constant_NOTIFICATION_PREDELETE:
  139. - **NOTIFICATION_POSTINITIALIZE** = **0** --- Called right when the object is initialized. Not available in script.
  140. - **NOTIFICATION_PREDELETE** = **1** --- Called before the object is about to be deleted.
  141. Method Descriptions
  142. -------------------
  143. .. _class_Object_method__get:
  144. - :ref:`Variant<class_Variant>` **_get** **(** :ref:`String<class_String>` property **)** virtual
  145. Virtual method which can be overridden to customize the return value of :ref:`get<class_Object_method_get>`.
  146. Returns the given property. Returns ``null`` if the ``property`` does not exist.
  147. ----
  148. .. _class_Object_method__get_property_list:
  149. - :ref:`Array<class_Array>` **_get_property_list** **(** **)** virtual
  150. Virtual method which can be overridden to customize the return value of :ref:`get_property_list<class_Object_method_get_property_list>`.
  151. Returns the object's property list as an :ref:`Array<class_Array>` of dictionaries.
  152. Each property's :ref:`Dictionary<class_Dictionary>` must contain at least ``name: String`` and ``type: int`` (see :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>`) entries. Optionally, it can also include ``hint: int`` (see :ref:`PropertyHint<enum_@GlobalScope_PropertyHint>`), ``hint_string: String``, and ``usage: int`` (see :ref:`PropertyUsageFlags<enum_@GlobalScope_PropertyUsageFlags>`).
  153. ----
  154. .. _class_Object_method__init:
  155. - void **_init** **(** **)** virtual
  156. Called when the object is initialized.
  157. ----
  158. .. _class_Object_method__notification:
  159. - void **_notification** **(** :ref:`int<class_int>` what **)** virtual
  160. Called whenever the object receives a notification, which is identified in ``what`` by a constant. The base ``Object`` has two constants :ref:`NOTIFICATION_POSTINITIALIZE<class_Object_constant_NOTIFICATION_POSTINITIALIZE>` and :ref:`NOTIFICATION_PREDELETE<class_Object_constant_NOTIFICATION_PREDELETE>`, but subclasses such as :ref:`Node<class_Node>` define a lot more notifications which are also received by this method.
  161. ----
  162. .. _class_Object_method__set:
  163. - :ref:`bool<class_bool>` **_set** **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** virtual
  164. Virtual method which can be overridden to customize the return value of :ref:`set<class_Object_method_set>`.
  165. Sets a property. Returns ``true`` if the ``property`` exists.
  166. ----
  167. .. _class_Object_method__to_string:
  168. - :ref:`String<class_String>` **_to_string** **(** **)** virtual
  169. Virtual method which can be overridden to customize the return value of :ref:`to_string<class_Object_method_to_string>`, and thus the object's representation where it is converted to a string, e.g. with ``print(obj)``.
  170. Returns a :ref:`String<class_String>` representing the object. If not overridden, defaults to ``"[ClassName:RID]"``.
  171. ----
  172. .. _class_Object_method_add_user_signal:
  173. - void **add_user_signal** **(** :ref:`String<class_String>` signal, :ref:`Array<class_Array>` arguments=[ ] **)**
  174. Adds a user-defined ``signal``. Arguments are optional, but can be added as an :ref:`Array<class_Array>` of dictionaries, each containing ``name: String`` and ``type: int`` (see :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>`) entries.
  175. ----
  176. .. _class_Object_method_call:
  177. - :ref:`Variant<class_Variant>` **call** **(** :ref:`String<class_String>` method, ... **)** vararg
  178. 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:
  179. ::
  180. call("set", "position", Vector2(42.0, 0.0))
  181. ----
  182. .. _class_Object_method_call_deferred:
  183. - void **call_deferred** **(** :ref:`String<class_String>` method, ... **)** vararg
  184. Calls the ``method`` on the object during idle time. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example:
  185. ::
  186. call_deferred("set", "position", Vector2(42.0, 0.0))
  187. ----
  188. .. _class_Object_method_callv:
  189. - :ref:`Variant<class_Variant>` **callv** **(** :ref:`String<class_String>` method, :ref:`Array<class_Array>` arg_array **)**
  190. Calls the ``method`` on the object and returns the result. Contrarily to :ref:`call<class_Object_method_call>`, this method does not support a variable number of arguments but expects all parameters to be via a single :ref:`Array<class_Array>`.
  191. ::
  192. callv("set", [ "position", Vector2(42.0, 0.0) ])
  193. ----
  194. .. _class_Object_method_can_translate_messages:
  195. - :ref:`bool<class_bool>` **can_translate_messages** **(** **)** const
  196. Returns ``true`` if the object can translate strings. See :ref:`set_message_translation<class_Object_method_set_message_translation>` and :ref:`tr<class_Object_method_tr>`.
  197. ----
  198. .. _class_Object_method_connect:
  199. - :ref:`Error<enum_@GlobalScope_Error>` **connect** **(** :ref:`String<class_String>` signal, :ref:`Object<class_Object>` target, :ref:`String<class_String>` method, :ref:`Array<class_Array>` binds=[ ], :ref:`int<class_int>` flags=0 **)**
  200. Connects a ``signal`` to a ``method`` on a ``target`` object. Pass optional ``binds`` to the call as an :ref:`Array<class_Array>` of parameters. These parameters will be passed to the method after any parameter used in the call to :ref:`emit_signal<class_Object_method_emit_signal>`. Use ``flags`` to set deferred or one-shot connections. See :ref:`ConnectFlags<enum_Object_ConnectFlags>` constants.
  201. 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<class_Object_constant_CONNECT_REFERENCE_COUNTED>`. To avoid this, first, use :ref:`is_connected<class_Object_method_is_connected>` to check for existing connections.
  202. If the ``target`` is destroyed in the game's lifecycle, the connection will be lost.
  203. Examples:
  204. ::
  205. connect("pressed", self, "_on_Button_pressed") # BaseButton signal
  206. connect("text_entered", self, "_on_LineEdit_text_entered") # LineEdit signal
  207. connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # User-defined signal
  208. An example of the relationship between ``binds`` passed to :ref:`connect<class_Object_method_connect>` and parameters used when calling :ref:`emit_signal<class_Object_method_emit_signal>`:
  209. ::
  210. connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # weapon_type and damage are passed last
  211. emit_signal("hit", "Dark lord", 5) # "Dark lord" and 5 are passed first
  212. func _on_Player_hit(hit_by, level, weapon_type, damage):
  213. print("Hit by %s (lvl %d) with weapon %s for %d damage" % [hit_by, level, weapon_type, damage])
  214. ----
  215. .. _class_Object_method_disconnect:
  216. - void **disconnect** **(** :ref:`String<class_String>` signal, :ref:`Object<class_Object>` target, :ref:`String<class_String>` method **)**
  217. Disconnects a ``signal`` from a ``method`` on the given ``target``.
  218. If you try to disconnect a connection that does not exist, the method will throw an error. Use :ref:`is_connected<class_Object_method_is_connected>` to ensure that the connection exists.
  219. ----
  220. .. _class_Object_method_emit_signal:
  221. - void **emit_signal** **(** :ref:`String<class_String>` signal, ... **)** vararg
  222. 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:
  223. ::
  224. emit_signal("hit", weapon_type, damage)
  225. emit_signal("game_over")
  226. ----
  227. .. _class_Object_method_free:
  228. - void **free** **(** **)**
  229. Deletes the object from memory. Any pre-existing reference to the freed object will now return ``null``.
  230. ----
  231. .. _class_Object_method_get:
  232. - :ref:`Variant<class_Variant>` **get** **(** :ref:`String<class_String>` property **)** const
  233. Returns the :ref:`Variant<class_Variant>` value of the given ``property``. If the ``property`` doesn't exist, this will return ``null``.
  234. ----
  235. .. _class_Object_method_get_class:
  236. - :ref:`String<class_String>` **get_class** **(** **)** const
  237. Returns the object's class as a :ref:`String<class_String>`.
  238. ----
  239. .. _class_Object_method_get_incoming_connections:
  240. - :ref:`Array<class_Array>` **get_incoming_connections** **(** **)** const
  241. Returns an :ref:`Array<class_Array>` of dictionaries with information about signals that are connected to the object.
  242. Each :ref:`Dictionary<class_Dictionary>` contains three String entries:
  243. - ``source`` is a reference to the signal emitter.
  244. - ``signal_name`` is the name of the connected signal.
  245. - ``method_name`` is the name of the method to which the signal is connected.
  246. ----
  247. .. _class_Object_method_get_indexed:
  248. - :ref:`Variant<class_Variant>` **get_indexed** **(** :ref:`NodePath<class_NodePath>` property **)** const
  249. Gets the object's property indexed by the given :ref:`NodePath<class_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"``.
  250. ----
  251. .. _class_Object_method_get_instance_id:
  252. - :ref:`int<class_int>` **get_instance_id** **(** **)** const
  253. Returns the object's unique instance ID.
  254. This ID can be saved in :ref:`EncodedObjectAsID<class_EncodedObjectAsID>`, and can be used to retrieve the object instance with :ref:`@GDScript.instance_from_id<class_@GDScript_method_instance_from_id>`.
  255. ----
  256. .. _class_Object_method_get_meta:
  257. - :ref:`Variant<class_Variant>` **get_meta** **(** :ref:`String<class_String>` name **)** const
  258. Returns the object's metadata entry for the given ``name``.
  259. ----
  260. .. _class_Object_method_get_meta_list:
  261. - :ref:`PoolStringArray<class_PoolStringArray>` **get_meta_list** **(** **)** const
  262. Returns the object's metadata as a :ref:`PoolStringArray<class_PoolStringArray>`.
  263. ----
  264. .. _class_Object_method_get_method_list:
  265. - :ref:`Array<class_Array>` **get_method_list** **(** **)** const
  266. Returns the object's methods and their signatures as an :ref:`Array<class_Array>`.
  267. ----
  268. .. _class_Object_method_get_property_list:
  269. - :ref:`Array<class_Array>` **get_property_list** **(** **)** const
  270. Returns the object's property list as an :ref:`Array<class_Array>` of dictionaries.
  271. Each property's :ref:`Dictionary<class_Dictionary>` contain at least ``name: String`` and ``type: int`` (see :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>`) entries. Optionally, it can also include ``hint: int`` (see :ref:`PropertyHint<enum_@GlobalScope_PropertyHint>`), ``hint_string: String``, and ``usage: int`` (see :ref:`PropertyUsageFlags<enum_@GlobalScope_PropertyUsageFlags>`).
  272. ----
  273. .. _class_Object_method_get_script:
  274. - :ref:`Reference<class_Reference>` **get_script** **(** **)** const
  275. Returns the object's :ref:`Script<class_Script>` instance, or ``null`` if none is assigned.
  276. ----
  277. .. _class_Object_method_get_signal_connection_list:
  278. - :ref:`Array<class_Array>` **get_signal_connection_list** **(** :ref:`String<class_String>` signal **)** const
  279. Returns an :ref:`Array<class_Array>` of connections for the given ``signal``.
  280. ----
  281. .. _class_Object_method_get_signal_list:
  282. - :ref:`Array<class_Array>` **get_signal_list** **(** **)** const
  283. Returns the list of signals as an :ref:`Array<class_Array>` of dictionaries.
  284. ----
  285. .. _class_Object_method_has_meta:
  286. - :ref:`bool<class_bool>` **has_meta** **(** :ref:`String<class_String>` name **)** const
  287. Returns ``true`` if a metadata entry is found with the given ``name``.
  288. ----
  289. .. _class_Object_method_has_method:
  290. - :ref:`bool<class_bool>` **has_method** **(** :ref:`String<class_String>` method **)** const
  291. Returns ``true`` if the object contains the given ``method``.
  292. ----
  293. .. _class_Object_method_has_user_signal:
  294. - :ref:`bool<class_bool>` **has_user_signal** **(** :ref:`String<class_String>` signal **)** const
  295. Returns ``true`` if the given user-defined ``signal`` exists.
  296. ----
  297. .. _class_Object_method_is_blocking_signals:
  298. - :ref:`bool<class_bool>` **is_blocking_signals** **(** **)** const
  299. Returns ``true`` if signal emission blocking is enabled.
  300. ----
  301. .. _class_Object_method_is_class:
  302. - :ref:`bool<class_bool>` **is_class** **(** :ref:`String<class_String>` class **)** const
  303. Returns ``true`` if the object inherits from the given ``class``.
  304. ----
  305. .. _class_Object_method_is_connected:
  306. - :ref:`bool<class_bool>` **is_connected** **(** :ref:`String<class_String>` signal, :ref:`Object<class_Object>` target, :ref:`String<class_String>` method **)** const
  307. Returns ``true`` if a connection exists for a given ``signal``, ``target``, and ``method``.
  308. ----
  309. .. _class_Object_method_is_queued_for_deletion:
  310. - :ref:`bool<class_bool>` **is_queued_for_deletion** **(** **)** const
  311. Returns ``true`` if the :ref:`Node.queue_free<class_Node_method_queue_free>` method was called for the object.
  312. ----
  313. .. _class_Object_method_notification:
  314. - void **notification** **(** :ref:`int<class_int>` what, :ref:`bool<class_bool>` reversed=false **)**
  315. Send a given notification to the object, which will also trigger a call to the :ref:`_notification<class_Object_method__notification>` method of all classes that the object inherits from.
  316. If ``reversed`` is ``true``, :ref:`_notification<class_Object_method__notification>` is called first on the object's own class, and then up to its successive parent classes. If ``reversed`` is ``false``, :ref:`_notification<class_Object_method__notification>` is called first on the highest ancestor (``Object`` itself), and then down to its successive inheriting classes.
  317. ----
  318. .. _class_Object_method_property_list_changed_notify:
  319. - void **property_list_changed_notify** **(** **)**
  320. 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.
  321. ----
  322. .. _class_Object_method_remove_meta:
  323. - void **remove_meta** **(** :ref:`String<class_String>` name **)**
  324. Removes a given entry from the object's metadata.
  325. ----
  326. .. _class_Object_method_set:
  327. - void **set** **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)**
  328. Assigns a new value to the given property. If the ``property`` does not exist, nothing will happen.
  329. ----
  330. .. _class_Object_method_set_block_signals:
  331. - void **set_block_signals** **(** :ref:`bool<class_bool>` enable **)**
  332. If set to ``true``, signal emission is blocked.
  333. ----
  334. .. _class_Object_method_set_deferred:
  335. - void **set_deferred** **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)**
  336. Assigns a new value to the given property, after the current frame's physics step. This is equivalent to calling :ref:`set<class_Object_method_set>` via :ref:`call_deferred<class_Object_method_call_deferred>`, i.e. ``call_deferred("set", property, value)``.
  337. ----
  338. .. _class_Object_method_set_indexed:
  339. - void **set_indexed** **(** :ref:`NodePath<class_NodePath>` property, :ref:`Variant<class_Variant>` value **)**
  340. Assigns a new value to the property identified by the :ref:`NodePath<class_NodePath>`. The node path should be relative to the current object and can use the colon character (``:``) to access nested properties. Example:
  341. ::
  342. set_indexed("position", Vector2(42, 0))
  343. set_indexed("position:y", -10)
  344. print(position) # (42, -10)
  345. ----
  346. .. _class_Object_method_set_message_translation:
  347. - void **set_message_translation** **(** :ref:`bool<class_bool>` enable **)**
  348. Defines whether the object can translate strings (with calls to :ref:`tr<class_Object_method_tr>`). Enabled by default.
  349. ----
  350. .. _class_Object_method_set_meta:
  351. - void **set_meta** **(** :ref:`String<class_String>` name, :ref:`Variant<class_Variant>` value **)**
  352. Adds or changes a given entry in the object's metadata. Metadata are serialized, and can take any :ref:`Variant<class_Variant>` value.
  353. ----
  354. .. _class_Object_method_set_script:
  355. - void **set_script** **(** :ref:`Reference<class_Reference>` script **)**
  356. Assigns a script to the object. Each object can have a single script assigned to it, which are used to extend its functionality.
  357. If the object already had a script, the previous script instance will be freed and its variables and state will be lost. The new script's :ref:`_init<class_Object_method__init>` method will be called.
  358. ----
  359. .. _class_Object_method_to_string:
  360. - :ref:`String<class_String>` **to_string** **(** **)**
  361. Returns a :ref:`String<class_String>` representing the object. If not overridden, defaults to ``"[ClassName:RID]"``.
  362. Override the method :ref:`_to_string<class_Object_method__to_string>` to customize the :ref:`String<class_String>` representation.
  363. ----
  364. .. _class_Object_method_tr:
  365. - :ref:`String<class_String>` **tr** **(** :ref:`String<class_String>` message **)** const
  366. Translates a message using translation catalogs configured in the Project Settings.
  367. Only works if message translation is enabled (which it is by default), otherwise it returns the ``message`` unchanged. See :ref:`set_message_translation<class_Object_method_set_message_translation>`.