class_object.rst 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Object.xml.
  6. .. _class_Object:
  7. Object
  8. ======
  9. **Inherited By:** :ref:`ARVRServer<class_ARVRServer>`, :ref:`AudioServer<class_AudioServer>`, :ref:`CameraServer<class_CameraServer>`, :ref:`ClassDB<class_ClassDB>`, :ref:`EditorFileSystemDirectory<class_EditorFileSystemDirectory>`, :ref:`EditorSelection<class_EditorSelection>`, :ref:`EditorVCSInterface<class_EditorVCSInterface>`, :ref:`Engine<class_Engine>`, :ref:`Geometry<class_Geometry>`, :ref:`GodotSharp<class_GodotSharp>`, :ref:`Input<class_Input>`, :ref:`InputMap<class_InputMap>`, :ref:`IP<class_IP>`, :ref:`JavaClassWrapper<class_JavaClassWrapper>`, :ref:`JavaScript<class_JavaScript>`, :ref:`JNISingleton<class_JNISingleton>`, :ref:`JSON<class_JSON>`, :ref:`JSONRPC<class_JSONRPC>`, :ref:`MainLoop<class_MainLoop>`, :ref:`Marshalls<class_Marshalls>`, :ref:`Navigation2DServer<class_Navigation2DServer>`, :ref:`NavigationMeshGenerator<class_NavigationMeshGenerator>`, :ref:`NavigationServer<class_NavigationServer>`, :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:`Time<class_Time>`, :ref:`TranslationServer<class_TranslationServer>`, :ref:`TreeItem<class_TreeItem>`, :ref:`UndoRedo<class_UndoRedo>`, :ref:`VisualScriptEditor<class_VisualScriptEditor>`, :ref:`VisualServer<class_VisualServer>`
  10. Base class for all non-built-in types.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Every class which is not a built-in type inherits from this class.
  15. You can construct Objects from scripting languages, using ``Object.new()`` in GDScript, ``new Object`` in C#, or the "Construct Object" node in VisualScript.
  16. 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++.
  17. 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.
  18. 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.
  19. Property membership can be tested directly in GDScript using ``in``:
  20. ::
  21. var n = Node2D.new()
  22. print("position" in n) # Prints "True".
  23. print("other_property" in n) # Prints "False".
  24. The ``in`` operator will evaluate to ``true`` as long as the key exists, even if the value is ``null``.
  25. 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>`.
  26. \ **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**.
  27. \ **Note:** Due to a bug, you can't create a "plain" Object using ``Object.new()``. Instead, use ``ClassDB.instance("Object")``. This bug only applies to Object itself, not any of its descendents like :ref:`Reference<class_Reference>`.
  28. .. rst-class:: classref-introduction-group
  29. Tutorials
  30. ---------
  31. - :doc:`When and how to avoid using nodes for everything <../tutorials/best_practices/node_alternatives>`
  32. - `Advanced exports using _get_property_list() <../tutorials/scripting/gdscript/gdscript_exports.html#advanced-exports>`__
  33. .. rst-class:: classref-reftable-group
  34. Methods
  35. -------
  36. .. table::
  37. :widths: auto
  38. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Variant<class_Variant>` | :ref:`_get<class_Object_method__get>` **(** :ref:`String<class_String>` property **)** |virtual| |
  40. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Array<class_Array>` | :ref:`_get_property_list<class_Object_method__get_property_list>` **(** **)** |virtual| |
  42. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`_init<class_Object_method__init>` **(** **)** |virtual| |
  44. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`_notification<class_Object_method__notification>` **(** :ref:`int<class_int>` what **)** |virtual| |
  46. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`_set<class_Object_method__set>` **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** |virtual| |
  48. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`String<class_String>` | :ref:`_to_string<class_Object_method__to_string>` **(** **)** |virtual| |
  50. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`add_user_signal<class_Object_method_add_user_signal>` **(** :ref:`String<class_String>` signal, :ref:`Array<class_Array>` arguments=[ ] **)** |
  52. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`Variant<class_Variant>` | :ref:`call<class_Object_method_call>` **(** :ref:`String<class_String>` method, ... **)** |vararg| |
  54. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`call_deferred<class_Object_method_call_deferred>` **(** :ref:`String<class_String>` method, ... **)** |vararg| |
  56. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`Variant<class_Variant>` | :ref:`callv<class_Object_method_callv>` **(** :ref:`String<class_String>` method, :ref:`Array<class_Array>` arg_array **)** |
  58. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`bool<class_bool>` | :ref:`can_translate_messages<class_Object_method_can_translate_messages>` **(** **)** |const| |
  60. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :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 **)** |
  62. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`disconnect<class_Object_method_disconnect>` **(** :ref:`String<class_String>` signal, :ref:`Object<class_Object>` target, :ref:`String<class_String>` method **)** |
  64. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`emit_signal<class_Object_method_emit_signal>` **(** :ref:`String<class_String>` signal, ... **)** |vararg| |
  66. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`free<class_Object_method_free>` **(** **)** |
  68. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`Variant<class_Variant>` | :ref:`get<class_Object_method_get>` **(** :ref:`String<class_String>` property **)** |const| |
  70. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`String<class_String>` | :ref:`get_class<class_Object_method_get_class>` **(** **)** |const| |
  72. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`Array<class_Array>` | :ref:`get_incoming_connections<class_Object_method_get_incoming_connections>` **(** **)** |const| |
  74. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`Variant<class_Variant>` | :ref:`get_indexed<class_Object_method_get_indexed>` **(** :ref:`NodePath<class_NodePath>` property_path **)** |const| |
  76. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`int<class_int>` | :ref:`get_instance_id<class_Object_method_get_instance_id>` **(** **)** |const| |
  78. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`Variant<class_Variant>` | :ref:`get_meta<class_Object_method_get_meta>` **(** :ref:`String<class_String>` name, :ref:`Variant<class_Variant>` default=null **)** |const| |
  80. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`PoolStringArray<class_PoolStringArray>` | :ref:`get_meta_list<class_Object_method_get_meta_list>` **(** **)** |const| |
  82. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`Array<class_Array>` | :ref:`get_method_list<class_Object_method_get_method_list>` **(** **)** |const| |
  84. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | :ref:`Array<class_Array>` | :ref:`get_property_list<class_Object_method_get_property_list>` **(** **)** |const| |
  86. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | :ref:`Reference<class_Reference>` | :ref:`get_script<class_Object_method_get_script>` **(** **)** |const| |
  88. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | :ref:`Array<class_Array>` | :ref:`get_signal_connection_list<class_Object_method_get_signal_connection_list>` **(** :ref:`String<class_String>` signal **)** |const| |
  90. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`Array<class_Array>` | :ref:`get_signal_list<class_Object_method_get_signal_list>` **(** **)** |const| |
  92. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`bool<class_bool>` | :ref:`has_meta<class_Object_method_has_meta>` **(** :ref:`String<class_String>` name **)** |const| |
  94. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`bool<class_bool>` | :ref:`has_method<class_Object_method_has_method>` **(** :ref:`String<class_String>` method **)** |const| |
  96. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :ref:`bool<class_bool>` | :ref:`has_signal<class_Object_method_has_signal>` **(** :ref:`String<class_String>` signal **)** |const| |
  98. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | :ref:`bool<class_bool>` | :ref:`has_user_signal<class_Object_method_has_user_signal>` **(** :ref:`String<class_String>` signal **)** |const| |
  100. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | :ref:`bool<class_bool>` | :ref:`is_blocking_signals<class_Object_method_is_blocking_signals>` **(** **)** |const| |
  102. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | :ref:`bool<class_bool>` | :ref:`is_class<class_Object_method_is_class>` **(** :ref:`String<class_String>` class **)** |const| |
  104. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | :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| |
  106. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | :ref:`bool<class_bool>` | :ref:`is_queued_for_deletion<class_Object_method_is_queued_for_deletion>` **(** **)** |const| |
  108. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. | void | :ref:`notification<class_Object_method_notification>` **(** :ref:`int<class_int>` what, :ref:`bool<class_bool>` reversed=false **)** |
  110. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  111. | void | :ref:`property_list_changed_notify<class_Object_method_property_list_changed_notify>` **(** **)** |
  112. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  113. | void | :ref:`remove_meta<class_Object_method_remove_meta>` **(** :ref:`String<class_String>` name **)** |
  114. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  115. | void | :ref:`set<class_Object_method_set>` **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** |
  116. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  117. | void | :ref:`set_block_signals<class_Object_method_set_block_signals>` **(** :ref:`bool<class_bool>` enable **)** |
  118. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  119. | void | :ref:`set_deferred<class_Object_method_set_deferred>` **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** |
  120. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  121. | void | :ref:`set_indexed<class_Object_method_set_indexed>` **(** :ref:`NodePath<class_NodePath>` property_path, :ref:`Variant<class_Variant>` value **)** |
  122. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  123. | void | :ref:`set_message_translation<class_Object_method_set_message_translation>` **(** :ref:`bool<class_bool>` enable **)** |
  124. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  125. | void | :ref:`set_meta<class_Object_method_set_meta>` **(** :ref:`String<class_String>` name, :ref:`Variant<class_Variant>` value **)** |
  126. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  127. | void | :ref:`set_script<class_Object_method_set_script>` **(** :ref:`Reference<class_Reference>` script **)** |
  128. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  129. | :ref:`String<class_String>` | :ref:`to_string<class_Object_method_to_string>` **(** **)** |
  130. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  131. | :ref:`String<class_String>` | :ref:`tr<class_Object_method_tr>` **(** :ref:`String<class_String>` message **)** |const| |
  132. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  133. .. rst-class:: classref-section-separator
  134. ----
  135. .. rst-class:: classref-descriptions-group
  136. Signals
  137. -------
  138. .. _class_Object_signal_script_changed:
  139. .. rst-class:: classref-signal
  140. **script_changed** **(** **)**
  141. Emitted whenever the object's script is changed.
  142. .. rst-class:: classref-section-separator
  143. ----
  144. .. rst-class:: classref-descriptions-group
  145. Enumerations
  146. ------------
  147. .. _enum_Object_ConnectFlags:
  148. .. rst-class:: classref-enumeration
  149. enum **ConnectFlags**:
  150. .. _class_Object_constant_CONNECT_DEFERRED:
  151. .. rst-class:: classref-enumeration-constant
  152. :ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_DEFERRED** = ``1``
  153. Connects a signal in deferred mode. This way, signal emissions are stored in a queue, then set on idle time.
  154. .. _class_Object_constant_CONNECT_PERSIST:
  155. .. rst-class:: classref-enumeration-constant
  156. :ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_PERSIST** = ``2``
  157. Persisting connections are saved when the object is serialized to file.
  158. .. _class_Object_constant_CONNECT_ONESHOT:
  159. .. rst-class:: classref-enumeration-constant
  160. :ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_ONESHOT** = ``4``
  161. One-shot connections disconnect themselves after emission.
  162. .. _class_Object_constant_CONNECT_REFERENCE_COUNTED:
  163. .. rst-class:: classref-enumeration-constant
  164. :ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_REFERENCE_COUNTED** = ``8``
  165. 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.
  166. .. rst-class:: classref-section-separator
  167. ----
  168. .. rst-class:: classref-descriptions-group
  169. Constants
  170. ---------
  171. .. _class_Object_constant_NOTIFICATION_POSTINITIALIZE:
  172. .. rst-class:: classref-constant
  173. **NOTIFICATION_POSTINITIALIZE** = ``0``
  174. Called right when the object is initialized. Not available in script.
  175. .. _class_Object_constant_NOTIFICATION_PREDELETE:
  176. .. rst-class:: classref-constant
  177. **NOTIFICATION_PREDELETE** = ``1``
  178. Called before the object is about to be deleted.
  179. .. rst-class:: classref-section-separator
  180. ----
  181. .. rst-class:: classref-descriptions-group
  182. Method Descriptions
  183. -------------------
  184. .. _class_Object_method__get:
  185. .. rst-class:: classref-method
  186. :ref:`Variant<class_Variant>` **_get** **(** :ref:`String<class_String>` property **)** |virtual|
  187. Virtual method which can be overridden to customize the return value of :ref:`get<class_Object_method_get>`.
  188. Returns the given property. Returns ``null`` if the ``property`` does not exist.
  189. .. rst-class:: classref-item-separator
  190. ----
  191. .. _class_Object_method__get_property_list:
  192. .. rst-class:: classref-method
  193. :ref:`Array<class_Array>` **_get_property_list** **(** **)** |virtual|
  194. Virtual method which can be overridden to customize the return value of :ref:`get_property_list<class_Object_method_get_property_list>`.
  195. Returns the object's property list as an :ref:`Array<class_Array>` of dictionaries.
  196. 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>`).
  197. .. rst-class:: classref-item-separator
  198. ----
  199. .. _class_Object_method__init:
  200. .. rst-class:: classref-method
  201. void **_init** **(** **)** |virtual|
  202. Called when the object is initialized in memory. Can be defined to take in parameters, that are passed in when constructing.
  203. \ **Note:** If :ref:`_init<class_Object_method__init>` is defined with required parameters, then explicit construction is the only valid means of creating an Object of the class. If any other means (such as :ref:`PackedScene.instance<class_PackedScene_method_instance>`) is used, then initialization will fail.
  204. .. rst-class:: classref-item-separator
  205. ----
  206. .. _class_Object_method__notification:
  207. .. rst-class:: classref-method
  208. void **_notification** **(** :ref:`int<class_int>` what **)** |virtual|
  209. 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.
  210. .. rst-class:: classref-item-separator
  211. ----
  212. .. _class_Object_method__set:
  213. .. rst-class:: classref-method
  214. :ref:`bool<class_bool>` **_set** **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** |virtual|
  215. Virtual method which can be overridden to customize the return value of :ref:`set<class_Object_method_set>`.
  216. Sets a property. Returns ``true`` if the ``property`` exists.
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_Object_method__to_string:
  220. .. rst-class:: classref-method
  221. :ref:`String<class_String>` **_to_string** **(** **)** |virtual|
  222. 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)``.
  223. Returns a :ref:`String<class_String>` representing the object. If not overridden, defaults to ``"[ClassName:RID]"``.
  224. .. rst-class:: classref-item-separator
  225. ----
  226. .. _class_Object_method_add_user_signal:
  227. .. rst-class:: classref-method
  228. void **add_user_signal** **(** :ref:`String<class_String>` signal, :ref:`Array<class_Array>` arguments=[ ] **)**
  229. 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.
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_Object_method_call:
  233. .. rst-class:: classref-method
  234. :ref:`Variant<class_Variant>` **call** **(** :ref:`String<class_String>` method, ... **)** |vararg|
  235. 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:
  236. ::
  237. call("set", "position", Vector2(42.0, 0.0))
  238. \ **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).
  239. .. rst-class:: classref-item-separator
  240. ----
  241. .. _class_Object_method_call_deferred:
  242. .. rst-class:: classref-method
  243. void **call_deferred** **(** :ref:`String<class_String>` method, ... **)** |vararg|
  244. 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:
  245. ::
  246. call_deferred("set", "position", Vector2(42.0, 0.0))
  247. \ **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).
  248. .. rst-class:: classref-item-separator
  249. ----
  250. .. _class_Object_method_callv:
  251. .. rst-class:: classref-method
  252. :ref:`Variant<class_Variant>` **callv** **(** :ref:`String<class_String>` method, :ref:`Array<class_Array>` arg_array **)**
  253. 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>`.
  254. ::
  255. callv("set", [ "position", Vector2(42.0, 0.0) ])
  256. .. rst-class:: classref-item-separator
  257. ----
  258. .. _class_Object_method_can_translate_messages:
  259. .. rst-class:: classref-method
  260. :ref:`bool<class_bool>` **can_translate_messages** **(** **)** |const|
  261. 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>`.
  262. .. rst-class:: classref-item-separator
  263. ----
  264. .. _class_Object_method_connect:
  265. .. rst-class:: classref-method
  266. :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 **)**
  267. 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.
  268. A ``signal`` can only be connected once to a ``method``. It will print 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.
  269. If the ``target`` is destroyed in the game's lifecycle, the connection will be lost.
  270. Examples:
  271. ::
  272. connect("pressed", self, "_on_Button_pressed") # BaseButton signal
  273. connect("text_entered", self, "_on_LineEdit_text_entered") # LineEdit signal
  274. connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # User-defined signal
  275. 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>`:
  276. ::
  277. connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # weapon_type and damage are passed last
  278. emit_signal("hit", "Dark lord", 5) # "Dark lord" and 5 are passed first
  279. func _on_Player_hit(hit_by, level, weapon_type, damage):
  280. print("Hit by %s (lvl %d) with weapon %s for %d damage" % [hit_by, level, weapon_type, damage])
  281. .. rst-class:: classref-item-separator
  282. ----
  283. .. _class_Object_method_disconnect:
  284. .. rst-class:: classref-method
  285. void **disconnect** **(** :ref:`String<class_String>` signal, :ref:`Object<class_Object>` target, :ref:`String<class_String>` method **)**
  286. Disconnects a ``signal`` from a ``method`` on the given ``target``.
  287. If you try to disconnect a connection that does not exist, the method will print an error. Use :ref:`is_connected<class_Object_method_is_connected>` to ensure that the connection exists.
  288. .. rst-class:: classref-item-separator
  289. ----
  290. .. _class_Object_method_emit_signal:
  291. .. rst-class:: classref-method
  292. void **emit_signal** **(** :ref:`String<class_String>` signal, ... **)** |vararg|
  293. 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:
  294. ::
  295. emit_signal("hit", weapon_type, damage)
  296. emit_signal("game_over")
  297. .. rst-class:: classref-item-separator
  298. ----
  299. .. _class_Object_method_free:
  300. .. rst-class:: classref-method
  301. void **free** **(** **)**
  302. Deletes the object from memory immediately. For :ref:`Node<class_Node>`\ s, you may want to use :ref:`Node.queue_free<class_Node_method_queue_free>` to queue the node for safe deletion at the end of the current frame.
  303. \ **Important:** If you have a variable pointing to an object, it will *not* be assigned to ``null`` once the object is freed. Instead, it will point to a *previously freed instance* and you should validate it with :ref:`@GDScript.is_instance_valid<class_@GDScript_method_is_instance_valid>` before attempting to call its methods or access its properties.
  304. .. rst-class:: classref-item-separator
  305. ----
  306. .. _class_Object_method_get:
  307. .. rst-class:: classref-method
  308. :ref:`Variant<class_Variant>` **get** **(** :ref:`String<class_String>` property **)** |const|
  309. Returns the :ref:`Variant<class_Variant>` value of the given ``property``. If the ``property`` doesn't exist, this will return ``null``.
  310. \ **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).
  311. .. rst-class:: classref-item-separator
  312. ----
  313. .. _class_Object_method_get_class:
  314. .. rst-class:: classref-method
  315. :ref:`String<class_String>` **get_class** **(** **)** |const|
  316. Returns the object's class as a :ref:`String<class_String>`. See also :ref:`is_class<class_Object_method_is_class>`.
  317. \ **Note:** :ref:`get_class<class_Object_method_get_class>` does not take ``class_name`` declarations into account. If the object has a ``class_name`` defined, the base class name will be returned instead.
  318. .. rst-class:: classref-item-separator
  319. ----
  320. .. _class_Object_method_get_incoming_connections:
  321. .. rst-class:: classref-method
  322. :ref:`Array<class_Array>` **get_incoming_connections** **(** **)** |const|
  323. Returns an :ref:`Array<class_Array>` of dictionaries with information about signals that are connected to the object.
  324. Each :ref:`Dictionary<class_Dictionary>` contains three String entries:
  325. - ``source`` is a reference to the signal emitter.
  326. - ``signal_name`` is the name of the connected signal.
  327. - ``method_name`` is the name of the method to which the signal is connected.
  328. .. rst-class:: classref-item-separator
  329. ----
  330. .. _class_Object_method_get_indexed:
  331. .. rst-class:: classref-method
  332. :ref:`Variant<class_Variant>` **get_indexed** **(** :ref:`NodePath<class_NodePath>` property_path **)** |const|
  333. Gets the object's property indexed by the given ``property_path``. The path should be a :ref:`NodePath<class_NodePath>` relative to the current object and can use the colon character (``:``) to access nested properties. Examples: ``"position:x"`` or ``"material:next_pass:blend_mode"``.
  334. \ **Note:** Even though the method takes :ref:`NodePath<class_NodePath>` argument, it doesn't support actual paths to :ref:`Node<class_Node>`\ s in the scene tree, only colon-separated sub-property paths. For the purpose of nodes, use :ref:`Node.get_node_and_resource<class_Node_method_get_node_and_resource>` instead.
  335. .. rst-class:: classref-item-separator
  336. ----
  337. .. _class_Object_method_get_instance_id:
  338. .. rst-class:: classref-method
  339. :ref:`int<class_int>` **get_instance_id** **(** **)** |const|
  340. Returns the object's unique instance ID.
  341. 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>`.
  342. .. rst-class:: classref-item-separator
  343. ----
  344. .. _class_Object_method_get_meta:
  345. .. rst-class:: classref-method
  346. :ref:`Variant<class_Variant>` **get_meta** **(** :ref:`String<class_String>` name, :ref:`Variant<class_Variant>` default=null **)** |const|
  347. Returns the object's metadata entry for the given ``name``.
  348. Throws error if the entry does not exist, unless ``default`` is not ``null`` (in which case the default value will be returned).
  349. .. rst-class:: classref-item-separator
  350. ----
  351. .. _class_Object_method_get_meta_list:
  352. .. rst-class:: classref-method
  353. :ref:`PoolStringArray<class_PoolStringArray>` **get_meta_list** **(** **)** |const|
  354. Returns the object's metadata as a :ref:`PoolStringArray<class_PoolStringArray>`.
  355. .. rst-class:: classref-item-separator
  356. ----
  357. .. _class_Object_method_get_method_list:
  358. .. rst-class:: classref-method
  359. :ref:`Array<class_Array>` **get_method_list** **(** **)** |const|
  360. Returns the object's methods and their signatures as an :ref:`Array<class_Array>`.
  361. .. rst-class:: classref-item-separator
  362. ----
  363. .. _class_Object_method_get_property_list:
  364. .. rst-class:: classref-method
  365. :ref:`Array<class_Array>` **get_property_list** **(** **)** |const|
  366. Returns the object's property list as an :ref:`Array<class_Array>` of dictionaries.
  367. 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>`).
  368. .. rst-class:: classref-item-separator
  369. ----
  370. .. _class_Object_method_get_script:
  371. .. rst-class:: classref-method
  372. :ref:`Reference<class_Reference>` **get_script** **(** **)** |const|
  373. Returns the object's :ref:`Script<class_Script>` instance, or ``null`` if none is assigned.
  374. .. rst-class:: classref-item-separator
  375. ----
  376. .. _class_Object_method_get_signal_connection_list:
  377. .. rst-class:: classref-method
  378. :ref:`Array<class_Array>` **get_signal_connection_list** **(** :ref:`String<class_String>` signal **)** |const|
  379. Returns an :ref:`Array<class_Array>` of connections for the given ``signal``.
  380. .. rst-class:: classref-item-separator
  381. ----
  382. .. _class_Object_method_get_signal_list:
  383. .. rst-class:: classref-method
  384. :ref:`Array<class_Array>` **get_signal_list** **(** **)** |const|
  385. Returns the list of signals as an :ref:`Array<class_Array>` of dictionaries.
  386. .. rst-class:: classref-item-separator
  387. ----
  388. .. _class_Object_method_has_meta:
  389. .. rst-class:: classref-method
  390. :ref:`bool<class_bool>` **has_meta** **(** :ref:`String<class_String>` name **)** |const|
  391. Returns ``true`` if a metadata entry is found with the given ``name``.
  392. .. rst-class:: classref-item-separator
  393. ----
  394. .. _class_Object_method_has_method:
  395. .. rst-class:: classref-method
  396. :ref:`bool<class_bool>` **has_method** **(** :ref:`String<class_String>` method **)** |const|
  397. Returns ``true`` if the object contains the given ``method``.
  398. .. rst-class:: classref-item-separator
  399. ----
  400. .. _class_Object_method_has_signal:
  401. .. rst-class:: classref-method
  402. :ref:`bool<class_bool>` **has_signal** **(** :ref:`String<class_String>` signal **)** |const|
  403. Returns ``true`` if the given ``signal`` exists.
  404. .. rst-class:: classref-item-separator
  405. ----
  406. .. _class_Object_method_has_user_signal:
  407. .. rst-class:: classref-method
  408. :ref:`bool<class_bool>` **has_user_signal** **(** :ref:`String<class_String>` signal **)** |const|
  409. 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.
  410. .. rst-class:: classref-item-separator
  411. ----
  412. .. _class_Object_method_is_blocking_signals:
  413. .. rst-class:: classref-method
  414. :ref:`bool<class_bool>` **is_blocking_signals** **(** **)** |const|
  415. Returns ``true`` if signal emission blocking is enabled.
  416. .. rst-class:: classref-item-separator
  417. ----
  418. .. _class_Object_method_is_class:
  419. .. rst-class:: classref-method
  420. :ref:`bool<class_bool>` **is_class** **(** :ref:`String<class_String>` class **)** |const|
  421. Returns ``true`` if the object inherits from the given ``class``. See also :ref:`get_class<class_Object_method_get_class>`.
  422. \ **Note:** :ref:`is_class<class_Object_method_is_class>` does not take ``class_name`` declarations into account. If the object has a ``class_name`` defined, :ref:`is_class<class_Object_method_is_class>` will return ``false`` for that name.
  423. .. rst-class:: classref-item-separator
  424. ----
  425. .. _class_Object_method_is_connected:
  426. .. rst-class:: classref-method
  427. :ref:`bool<class_bool>` **is_connected** **(** :ref:`String<class_String>` signal, :ref:`Object<class_Object>` target, :ref:`String<class_String>` method **)** |const|
  428. Returns ``true`` if a connection exists for a given ``signal``, ``target``, and ``method``.
  429. .. rst-class:: classref-item-separator
  430. ----
  431. .. _class_Object_method_is_queued_for_deletion:
  432. .. rst-class:: classref-method
  433. :ref:`bool<class_bool>` **is_queued_for_deletion** **(** **)** |const|
  434. Returns ``true`` if the :ref:`Node.queue_free<class_Node_method_queue_free>` method was called for the object.
  435. .. rst-class:: classref-item-separator
  436. ----
  437. .. _class_Object_method_notification:
  438. .. rst-class:: classref-method
  439. void **notification** **(** :ref:`int<class_int>` what, :ref:`bool<class_bool>` reversed=false **)**
  440. 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.
  441. 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.
  442. .. rst-class:: classref-item-separator
  443. ----
  444. .. _class_Object_method_property_list_changed_notify:
  445. .. rst-class:: classref-method
  446. void **property_list_changed_notify** **(** **)**
  447. 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.
  448. .. rst-class:: classref-item-separator
  449. ----
  450. .. _class_Object_method_remove_meta:
  451. .. rst-class:: classref-method
  452. void **remove_meta** **(** :ref:`String<class_String>` name **)**
  453. Removes a given entry from the object's metadata. See also :ref:`set_meta<class_Object_method_set_meta>`.
  454. .. rst-class:: classref-item-separator
  455. ----
  456. .. _class_Object_method_set:
  457. .. rst-class:: classref-method
  458. void **set** **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)**
  459. Assigns a new value to the given property. If the ``property`` does not exist or the given value's type doesn't match, nothing will happen.
  460. \ **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).
  461. .. rst-class:: classref-item-separator
  462. ----
  463. .. _class_Object_method_set_block_signals:
  464. .. rst-class:: classref-method
  465. void **set_block_signals** **(** :ref:`bool<class_bool>` enable **)**
  466. If set to ``true``, signal emission is blocked.
  467. .. rst-class:: classref-item-separator
  468. ----
  469. .. _class_Object_method_set_deferred:
  470. .. rst-class:: classref-method
  471. void **set_deferred** **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)**
  472. 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)``.
  473. \ **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).
  474. .. rst-class:: classref-item-separator
  475. ----
  476. .. _class_Object_method_set_indexed:
  477. .. rst-class:: classref-method
  478. void **set_indexed** **(** :ref:`NodePath<class_NodePath>` property_path, :ref:`Variant<class_Variant>` value **)**
  479. Assigns a new value to the property identified by the ``property_path``. The path should be a :ref:`NodePath<class_NodePath>` relative to the current object and can use the colon character (``:``) to access nested properties. Example:
  480. ::
  481. set_indexed("position", Vector2(42, 0))
  482. set_indexed("position:y", -10)
  483. print(position) # (42, -10)
  484. .. rst-class:: classref-item-separator
  485. ----
  486. .. _class_Object_method_set_message_translation:
  487. .. rst-class:: classref-method
  488. void **set_message_translation** **(** :ref:`bool<class_bool>` enable **)**
  489. Defines whether the object can translate strings (with calls to :ref:`tr<class_Object_method_tr>`). Enabled by default.
  490. .. rst-class:: classref-item-separator
  491. ----
  492. .. _class_Object_method_set_meta:
  493. .. rst-class:: classref-method
  494. void **set_meta** **(** :ref:`String<class_String>` name, :ref:`Variant<class_Variant>` value **)**
  495. Adds, changes or removes a given entry in the object's metadata. Metadata are serialized and can take any :ref:`Variant<class_Variant>` value.
  496. 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"``.
  497. .. rst-class:: classref-item-separator
  498. ----
  499. .. _class_Object_method_set_script:
  500. .. rst-class:: classref-method
  501. void **set_script** **(** :ref:`Reference<class_Reference>` script **)**
  502. Assigns a script to the object. Each object can have a single script assigned to it, which are used to extend its functionality.
  503. 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.
  504. .. rst-class:: classref-item-separator
  505. ----
  506. .. _class_Object_method_to_string:
  507. .. rst-class:: classref-method
  508. :ref:`String<class_String>` **to_string** **(** **)**
  509. Returns a :ref:`String<class_String>` representing the object. If not overridden, defaults to ``"[ClassName:RID]"``.
  510. Override the method :ref:`_to_string<class_Object_method__to_string>` to customize the :ref:`String<class_String>` representation.
  511. .. rst-class:: classref-item-separator
  512. ----
  513. .. _class_Object_method_tr:
  514. .. rst-class:: classref-method
  515. :ref:`String<class_String>` **tr** **(** :ref:`String<class_String>` message **)** |const|
  516. Translates a message using translation catalogs configured in the Project Settings.
  517. 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>`.
  518. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  519. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  520. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  521. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`