class_object.rst 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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:`JNISingleton<class_JNISingleton>`, :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. The ``in`` operator will evaluate to ``true`` as long as the key exists, even if the value is ``null``.
  23. 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>`.
  24. **Note:** Unlike references to a :ref:`Reference<class_Reference>`, references to an Object stored in a variable can become invalid without warning. Therefore, it's recommended to use :ref:`Reference<class_Reference>` for data classes instead of ``Object``.
  25. Tutorials
  26. ---------
  27. - :doc:`../getting_started/workflow/best_practices/node_alternatives`
  28. Methods
  29. -------
  30. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Variant<class_Variant>` | :ref:`_get<class_Object_method__get>` **(** :ref:`String<class_String>` property **)** |virtual| |
  32. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Array<class_Array>` | :ref:`_get_property_list<class_Object_method__get_property_list>` **(** **)** |virtual| |
  34. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | void | :ref:`_init<class_Object_method__init>` **(** **)** |virtual| |
  36. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | void | :ref:`_notification<class_Object_method__notification>` **(** :ref:`int<class_int>` what **)** |virtual| |
  38. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`bool<class_bool>` | :ref:`_set<class_Object_method__set>` **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** |virtual| |
  40. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`String<class_String>` | :ref:`_to_string<class_Object_method__to_string>` **(** **)** |virtual| |
  42. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`add_user_signal<class_Object_method_add_user_signal>` **(** :ref:`String<class_String>` signal, :ref:`Array<class_Array>` arguments=[ ] **)** |
  44. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Variant<class_Variant>` | :ref:`call<class_Object_method_call>` **(** :ref:`String<class_String>` method, ... **)** |vararg| |
  46. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`call_deferred<class_Object_method_call_deferred>` **(** :ref:`String<class_String>` method, ... **)** |vararg| |
  48. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Variant<class_Variant>` | :ref:`callv<class_Object_method_callv>` **(** :ref:`String<class_String>` method, :ref:`Array<class_Array>` arg_array **)** |
  50. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`bool<class_bool>` | :ref:`can_translate_messages<class_Object_method_can_translate_messages>` **(** **)** |const| |
  52. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :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 **)** |
  54. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`disconnect<class_Object_method_disconnect>` **(** :ref:`String<class_String>` signal, :ref:`Object<class_Object>` target, :ref:`String<class_String>` method **)** |
  56. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`emit_signal<class_Object_method_emit_signal>` **(** :ref:`String<class_String>` signal, ... **)** |vararg| |
  58. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`free<class_Object_method_free>` **(** **)** |
  60. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Variant<class_Variant>` | :ref:`get<class_Object_method_get>` **(** :ref:`String<class_String>` property **)** |const| |
  62. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`String<class_String>` | :ref:`get_class<class_Object_method_get_class>` **(** **)** |const| |
  64. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Array<class_Array>` | :ref:`get_incoming_connections<class_Object_method_get_incoming_connections>` **(** **)** |const| |
  66. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`Variant<class_Variant>` | :ref:`get_indexed<class_Object_method_get_indexed>` **(** :ref:`NodePath<class_NodePath>` property **)** |const| |
  68. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`int<class_int>` | :ref:`get_instance_id<class_Object_method_get_instance_id>` **(** **)** |const| |
  70. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`Variant<class_Variant>` | :ref:`get_meta<class_Object_method_get_meta>` **(** :ref:`String<class_String>` name **)** |const| |
  72. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`PoolStringArray<class_PoolStringArray>` | :ref:`get_meta_list<class_Object_method_get_meta_list>` **(** **)** |const| |
  74. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`Array<class_Array>` | :ref:`get_method_list<class_Object_method_get_method_list>` **(** **)** |const| |
  76. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`Array<class_Array>` | :ref:`get_property_list<class_Object_method_get_property_list>` **(** **)** |const| |
  78. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`Reference<class_Reference>` | :ref:`get_script<class_Object_method_get_script>` **(** **)** |const| |
  80. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`Array<class_Array>` | :ref:`get_signal_connection_list<class_Object_method_get_signal_connection_list>` **(** :ref:`String<class_String>` signal **)** |const| |
  82. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`Array<class_Array>` | :ref:`get_signal_list<class_Object_method_get_signal_list>` **(** **)** |const| |
  84. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | :ref:`bool<class_bool>` | :ref:`has_meta<class_Object_method_has_meta>` **(** :ref:`String<class_String>` name **)** |const| |
  86. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | :ref:`bool<class_bool>` | :ref:`has_method<class_Object_method_has_method>` **(** :ref:`String<class_String>` method **)** |const| |
  88. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | :ref:`bool<class_bool>` | :ref:`has_signal<class_Object_method_has_signal>` **(** :ref:`String<class_String>` signal **)** |const| |
  90. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`bool<class_bool>` | :ref:`has_user_signal<class_Object_method_has_user_signal>` **(** :ref:`String<class_String>` signal **)** |const| |
  92. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`bool<class_bool>` | :ref:`is_blocking_signals<class_Object_method_is_blocking_signals>` **(** **)** |const| |
  94. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`bool<class_bool>` | :ref:`is_class<class_Object_method_is_class>` **(** :ref:`String<class_String>` class **)** |const| |
  96. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :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| |
  98. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | :ref:`bool<class_bool>` | :ref:`is_queued_for_deletion<class_Object_method_is_queued_for_deletion>` **(** **)** |const| |
  100. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | void | :ref:`notification<class_Object_method_notification>` **(** :ref:`int<class_int>` what, :ref:`bool<class_bool>` reversed=false **)** |
  102. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | void | :ref:`property_list_changed_notify<class_Object_method_property_list_changed_notify>` **(** **)** |
  104. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | void | :ref:`remove_meta<class_Object_method_remove_meta>` **(** :ref:`String<class_String>` name **)** |
  106. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | void | :ref:`set<class_Object_method_set>` **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** |
  108. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. | void | :ref:`set_block_signals<class_Object_method_set_block_signals>` **(** :ref:`bool<class_bool>` enable **)** |
  110. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  111. | void | :ref:`set_deferred<class_Object_method_set_deferred>` **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** |
  112. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  113. | void | :ref:`set_indexed<class_Object_method_set_indexed>` **(** :ref:`NodePath<class_NodePath>` property, :ref:`Variant<class_Variant>` value **)** |
  114. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  115. | void | :ref:`set_message_translation<class_Object_method_set_message_translation>` **(** :ref:`bool<class_bool>` enable **)** |
  116. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  117. | void | :ref:`set_meta<class_Object_method_set_meta>` **(** :ref:`String<class_String>` name, :ref:`Variant<class_Variant>` value **)** |
  118. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  119. | void | :ref:`set_script<class_Object_method_set_script>` **(** :ref:`Reference<class_Reference>` script **)** |
  120. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  121. | :ref:`String<class_String>` | :ref:`to_string<class_Object_method_to_string>` **(** **)** |
  122. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  123. | :ref:`String<class_String>` | :ref:`tr<class_Object_method_tr>` **(** :ref:`String<class_String>` message **)** |const| |
  124. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  125. Signals
  126. -------
  127. .. _class_Object_signal_script_changed:
  128. - **script_changed** **(** **)**
  129. Emitted whenever the object's script is changed.
  130. Enumerations
  131. ------------
  132. .. _enum_Object_ConnectFlags:
  133. .. _class_Object_constant_CONNECT_DEFERRED:
  134. .. _class_Object_constant_CONNECT_PERSIST:
  135. .. _class_Object_constant_CONNECT_ONESHOT:
  136. .. _class_Object_constant_CONNECT_REFERENCE_COUNTED:
  137. enum **ConnectFlags**:
  138. - **CONNECT_DEFERRED** = **1** --- Connects a signal in deferred mode. This way, signal emissions are stored in a queue, then set on idle time.
  139. - **CONNECT_PERSIST** = **2** --- Persisting connections are saved when the object is serialized to file.
  140. - **CONNECT_ONESHOT** = **4** --- One-shot connections disconnect themselves after emission.
  141. - **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.
  142. Constants
  143. ---------
  144. .. _class_Object_constant_NOTIFICATION_POSTINITIALIZE:
  145. .. _class_Object_constant_NOTIFICATION_PREDELETE:
  146. - **NOTIFICATION_POSTINITIALIZE** = **0** --- Called right when the object is initialized. Not available in script.
  147. - **NOTIFICATION_PREDELETE** = **1** --- Called before the object is about to be deleted.
  148. Method Descriptions
  149. -------------------
  150. .. _class_Object_method__get:
  151. - :ref:`Variant<class_Variant>` **_get** **(** :ref:`String<class_String>` property **)** |virtual|
  152. Virtual method which can be overridden to customize the return value of :ref:`get<class_Object_method_get>`.
  153. Returns the given property. Returns ``null`` if the ``property`` does not exist.
  154. ----
  155. .. _class_Object_method__get_property_list:
  156. - :ref:`Array<class_Array>` **_get_property_list** **(** **)** |virtual|
  157. Virtual method which can be overridden to customize the return value of :ref:`get_property_list<class_Object_method_get_property_list>`.
  158. Returns the object's property list as an :ref:`Array<class_Array>` of dictionaries.
  159. 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>`).
  160. ----
  161. .. _class_Object_method__init:
  162. - void **_init** **(** **)** |virtual|
  163. Called when the object is initialized.
  164. ----
  165. .. _class_Object_method__notification:
  166. - void **_notification** **(** :ref:`int<class_int>` what **)** |virtual|
  167. 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.
  168. ----
  169. .. _class_Object_method__set:
  170. - :ref:`bool<class_bool>` **_set** **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** |virtual|
  171. Virtual method which can be overridden to customize the return value of :ref:`set<class_Object_method_set>`.
  172. Sets a property. Returns ``true`` if the ``property`` exists.
  173. ----
  174. .. _class_Object_method__to_string:
  175. - :ref:`String<class_String>` **_to_string** **(** **)** |virtual|
  176. 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)``.
  177. Returns a :ref:`String<class_String>` representing the object. If not overridden, defaults to ``"[ClassName:RID]"``.
  178. ----
  179. .. _class_Object_method_add_user_signal:
  180. - void **add_user_signal** **(** :ref:`String<class_String>` signal, :ref:`Array<class_Array>` arguments=[ ] **)**
  181. 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.
  182. ----
  183. .. _class_Object_method_call:
  184. - :ref:`Variant<class_Variant>` **call** **(** :ref:`String<class_String>` method, ... **)** |vararg|
  185. 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:
  186. ::
  187. call("set", "position", Vector2(42.0, 0.0))
  188. **Note:** In C#, the method name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined methods where you should use the same convention as in the C# source (typically PascalCase).
  189. ----
  190. .. _class_Object_method_call_deferred:
  191. - void **call_deferred** **(** :ref:`String<class_String>` method, ... **)** |vararg|
  192. 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:
  193. ::
  194. call_deferred("set", "position", Vector2(42.0, 0.0))
  195. **Note:** In C#, the method name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined methods where you should use the same convention as in the C# source (typically PascalCase).
  196. ----
  197. .. _class_Object_method_callv:
  198. - :ref:`Variant<class_Variant>` **callv** **(** :ref:`String<class_String>` method, :ref:`Array<class_Array>` arg_array **)**
  199. 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>`.
  200. ::
  201. callv("set", [ "position", Vector2(42.0, 0.0) ])
  202. ----
  203. .. _class_Object_method_can_translate_messages:
  204. - :ref:`bool<class_bool>` **can_translate_messages** **(** **)** |const|
  205. 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>`.
  206. ----
  207. .. _class_Object_method_connect:
  208. - :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 **)**
  209. 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.
  210. 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.
  211. If the ``target`` is destroyed in the game's lifecycle, the connection will be lost.
  212. Examples:
  213. ::
  214. connect("pressed", self, "_on_Button_pressed") # BaseButton signal
  215. connect("text_entered", self, "_on_LineEdit_text_entered") # LineEdit signal
  216. connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # User-defined signal
  217. 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>`:
  218. ::
  219. connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # weapon_type and damage are passed last
  220. emit_signal("hit", "Dark lord", 5) # "Dark lord" and 5 are passed first
  221. func _on_Player_hit(hit_by, level, weapon_type, damage):
  222. print("Hit by %s (lvl %d) with weapon %s for %d damage" % [hit_by, level, weapon_type, damage])
  223. ----
  224. .. _class_Object_method_disconnect:
  225. - void **disconnect** **(** :ref:`String<class_String>` signal, :ref:`Object<class_Object>` target, :ref:`String<class_String>` method **)**
  226. Disconnects a ``signal`` from a ``method`` on the given ``target``.
  227. 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.
  228. ----
  229. .. _class_Object_method_emit_signal:
  230. - void **emit_signal** **(** :ref:`String<class_String>` signal, ... **)** |vararg|
  231. 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:
  232. ::
  233. emit_signal("hit", weapon_type, damage)
  234. emit_signal("game_over")
  235. ----
  236. .. _class_Object_method_free:
  237. - void **free** **(** **)**
  238. Deletes the object from memory. Any pre-existing reference to the freed object will become invalid, e.g. ``is_instance_valid(object)`` will return ``false``.
  239. ----
  240. .. _class_Object_method_get:
  241. - :ref:`Variant<class_Variant>` **get** **(** :ref:`String<class_String>` property **)** |const|
  242. Returns the :ref:`Variant<class_Variant>` value of the given ``property``. If the ``property`` doesn't exist, this will return ``null``.
  243. **Note:** In C#, the property name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined properties where you should use the same convention as in the C# source (typically PascalCase).
  244. ----
  245. .. _class_Object_method_get_class:
  246. - :ref:`String<class_String>` **get_class** **(** **)** |const|
  247. Returns the object's class as a :ref:`String<class_String>`.
  248. ----
  249. .. _class_Object_method_get_incoming_connections:
  250. - :ref:`Array<class_Array>` **get_incoming_connections** **(** **)** |const|
  251. Returns an :ref:`Array<class_Array>` of dictionaries with information about signals that are connected to the object.
  252. Each :ref:`Dictionary<class_Dictionary>` contains three String entries:
  253. - ``source`` is a reference to the signal emitter.
  254. - ``signal_name`` is the name of the connected signal.
  255. - ``method_name`` is the name of the method to which the signal is connected.
  256. ----
  257. .. _class_Object_method_get_indexed:
  258. - :ref:`Variant<class_Variant>` **get_indexed** **(** :ref:`NodePath<class_NodePath>` property **)** |const|
  259. 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"``.
  260. ----
  261. .. _class_Object_method_get_instance_id:
  262. - :ref:`int<class_int>` **get_instance_id** **(** **)** |const|
  263. Returns the object's unique instance ID.
  264. 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>`.
  265. ----
  266. .. _class_Object_method_get_meta:
  267. - :ref:`Variant<class_Variant>` **get_meta** **(** :ref:`String<class_String>` name **)** |const|
  268. Returns the object's metadata entry for the given ``name``.
  269. ----
  270. .. _class_Object_method_get_meta_list:
  271. - :ref:`PoolStringArray<class_PoolStringArray>` **get_meta_list** **(** **)** |const|
  272. Returns the object's metadata as a :ref:`PoolStringArray<class_PoolStringArray>`.
  273. ----
  274. .. _class_Object_method_get_method_list:
  275. - :ref:`Array<class_Array>` **get_method_list** **(** **)** |const|
  276. Returns the object's methods and their signatures as an :ref:`Array<class_Array>`.
  277. ----
  278. .. _class_Object_method_get_property_list:
  279. - :ref:`Array<class_Array>` **get_property_list** **(** **)** |const|
  280. Returns the object's property list as an :ref:`Array<class_Array>` of dictionaries.
  281. 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>`).
  282. ----
  283. .. _class_Object_method_get_script:
  284. - :ref:`Reference<class_Reference>` **get_script** **(** **)** |const|
  285. Returns the object's :ref:`Script<class_Script>` instance, or ``null`` if none is assigned.
  286. ----
  287. .. _class_Object_method_get_signal_connection_list:
  288. - :ref:`Array<class_Array>` **get_signal_connection_list** **(** :ref:`String<class_String>` signal **)** |const|
  289. Returns an :ref:`Array<class_Array>` of connections for the given ``signal``.
  290. ----
  291. .. _class_Object_method_get_signal_list:
  292. - :ref:`Array<class_Array>` **get_signal_list** **(** **)** |const|
  293. Returns the list of signals as an :ref:`Array<class_Array>` of dictionaries.
  294. ----
  295. .. _class_Object_method_has_meta:
  296. - :ref:`bool<class_bool>` **has_meta** **(** :ref:`String<class_String>` name **)** |const|
  297. Returns ``true`` if a metadata entry is found with the given ``name``.
  298. ----
  299. .. _class_Object_method_has_method:
  300. - :ref:`bool<class_bool>` **has_method** **(** :ref:`String<class_String>` method **)** |const|
  301. Returns ``true`` if the object contains the given ``method``.
  302. ----
  303. .. _class_Object_method_has_signal:
  304. - :ref:`bool<class_bool>` **has_signal** **(** :ref:`String<class_String>` signal **)** |const|
  305. Returns ``true`` if the given ``signal`` exists.
  306. ----
  307. .. _class_Object_method_has_user_signal:
  308. - :ref:`bool<class_bool>` **has_user_signal** **(** :ref:`String<class_String>` signal **)** |const|
  309. Returns ``true`` if the given user-defined ``signal`` exists. Only signals added using :ref:`add_user_signal<class_Object_method_add_user_signal>` are taken into account.
  310. ----
  311. .. _class_Object_method_is_blocking_signals:
  312. - :ref:`bool<class_bool>` **is_blocking_signals** **(** **)** |const|
  313. Returns ``true`` if signal emission blocking is enabled.
  314. ----
  315. .. _class_Object_method_is_class:
  316. - :ref:`bool<class_bool>` **is_class** **(** :ref:`String<class_String>` class **)** |const|
  317. Returns ``true`` if the object inherits from the given ``class``.
  318. ----
  319. .. _class_Object_method_is_connected:
  320. - :ref:`bool<class_bool>` **is_connected** **(** :ref:`String<class_String>` signal, :ref:`Object<class_Object>` target, :ref:`String<class_String>` method **)** |const|
  321. Returns ``true`` if a connection exists for a given ``signal``, ``target``, and ``method``.
  322. ----
  323. .. _class_Object_method_is_queued_for_deletion:
  324. - :ref:`bool<class_bool>` **is_queued_for_deletion** **(** **)** |const|
  325. Returns ``true`` if the :ref:`Node.queue_free<class_Node_method_queue_free>` method was called for the object.
  326. ----
  327. .. _class_Object_method_notification:
  328. - void **notification** **(** :ref:`int<class_int>` what, :ref:`bool<class_bool>` reversed=false **)**
  329. 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.
  330. 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.
  331. ----
  332. .. _class_Object_method_property_list_changed_notify:
  333. - void **property_list_changed_notify** **(** **)**
  334. 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.
  335. ----
  336. .. _class_Object_method_remove_meta:
  337. - void **remove_meta** **(** :ref:`String<class_String>` name **)**
  338. Removes a given entry from the object's metadata. See also :ref:`set_meta<class_Object_method_set_meta>`.
  339. ----
  340. .. _class_Object_method_set:
  341. - void **set** **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)**
  342. Assigns a new value to the given property. If the ``property`` does not exist, nothing will happen.
  343. **Note:** In C#, the property name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined properties where you should use the same convention as in the C# source (typically PascalCase).
  344. ----
  345. .. _class_Object_method_set_block_signals:
  346. - void **set_block_signals** **(** :ref:`bool<class_bool>` enable **)**
  347. If set to ``true``, signal emission is blocked.
  348. ----
  349. .. _class_Object_method_set_deferred:
  350. - void **set_deferred** **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)**
  351. 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)``.
  352. **Note:** In C#, the property name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined properties where you should use the same convention as in the C# source (typically PascalCase).
  353. ----
  354. .. _class_Object_method_set_indexed:
  355. - void **set_indexed** **(** :ref:`NodePath<class_NodePath>` property, :ref:`Variant<class_Variant>` value **)**
  356. 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:
  357. ::
  358. set_indexed("position", Vector2(42, 0))
  359. set_indexed("position:y", -10)
  360. print(position) # (42, -10)
  361. ----
  362. .. _class_Object_method_set_message_translation:
  363. - void **set_message_translation** **(** :ref:`bool<class_bool>` enable **)**
  364. Defines whether the object can translate strings (with calls to :ref:`tr<class_Object_method_tr>`). Enabled by default.
  365. ----
  366. .. _class_Object_method_set_meta:
  367. - void **set_meta** **(** :ref:`String<class_String>` name, :ref:`Variant<class_Variant>` value **)**
  368. Adds, changes or removes a given entry in the object's metadata. Metadata are serialized and can take any :ref:`Variant<class_Variant>` value.
  369. To remove a given entry from the object's metadata, use :ref:`remove_meta<class_Object_method_remove_meta>`. Metadata is also removed if its value is set to ``null``. This means you can also use ``set_meta("name", null)`` to remove metadata for ``"name"``.
  370. ----
  371. .. _class_Object_method_set_script:
  372. - void **set_script** **(** :ref:`Reference<class_Reference>` script **)**
  373. Assigns a script to the object. Each object can have a single script assigned to it, which are used to extend its functionality.
  374. 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.
  375. ----
  376. .. _class_Object_method_to_string:
  377. - :ref:`String<class_String>` **to_string** **(** **)**
  378. Returns a :ref:`String<class_String>` representing the object. If not overridden, defaults to ``"[ClassName:RID]"``.
  379. Override the method :ref:`_to_string<class_Object_method__to_string>` to customize the :ref:`String<class_String>` representation.
  380. ----
  381. .. _class_Object_method_tr:
  382. - :ref:`String<class_String>` **tr** **(** :ref:`String<class_String>` message **)** |const|
  383. Translates a message using translation catalogs configured in the Project Settings.
  384. 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>`.
  385. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  386. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  387. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`