class_object.rst 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.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:`AudioServer<class_AudioServer>`, :ref:`CameraServer<class_CameraServer>`, :ref:`ClassDB<class_ClassDB>`, :ref:`DisplayServer<class_DisplayServer>`, :ref:`EditorFileSystemDirectory<class_EditorFileSystemDirectory>`, :ref:`EditorPaths<class_EditorPaths>`, :ref:`EditorSelection<class_EditorSelection>`, :ref:`EditorVCSInterface<class_EditorVCSInterface>`, :ref:`Engine<class_Engine>`, :ref:`EngineDebugger<class_EngineDebugger>`, :ref:`Geometry2D<class_Geometry2D>`, :ref:`Geometry3D<class_Geometry3D>`, :ref:`GodotSharp<class_GodotSharp>`, :ref:`IP<class_IP>`, :ref:`Input<class_Input>`, :ref:`InputMap<class_InputMap>`, :ref:`JNISingleton<class_JNISingleton>`, :ref:`JSONRPC<class_JSONRPC>`, :ref:`JavaClassWrapper<class_JavaClassWrapper>`, :ref:`JavaScript<class_JavaScript>`, :ref:`MainLoop<class_MainLoop>`, :ref:`Marshalls<class_Marshalls>`, :ref:`MultiplayerReplicator<class_MultiplayerReplicator>`, :ref:`NativeExtensionManager<class_NativeExtensionManager>`, :ref:`NavigationMeshGenerator<class_NavigationMeshGenerator>`, :ref:`NavigationServer2D<class_NavigationServer2D>`, :ref:`NavigationServer3D<class_NavigationServer3D>`, :ref:`Node<class_Node>`, :ref:`OS<class_OS>`, :ref:`Performance<class_Performance>`, :ref:`PhysicsDirectBodyState2D<class_PhysicsDirectBodyState2D>`, :ref:`PhysicsDirectBodyState3D<class_PhysicsDirectBodyState3D>`, :ref:`PhysicsDirectSpaceState2D<class_PhysicsDirectSpaceState2D>`, :ref:`PhysicsDirectSpaceState3D<class_PhysicsDirectSpaceState3D>`, :ref:`PhysicsServer2D<class_PhysicsServer2D>`, :ref:`PhysicsServer3D<class_PhysicsServer3D>`, :ref:`ProjectSettings<class_ProjectSettings>`, :ref:`RefCounted<class_RefCounted>`, :ref:`RenderingDevice<class_RenderingDevice>`, :ref:`RenderingServer<class_RenderingServer>`, :ref:`ResourceLoader<class_ResourceLoader>`, :ref:`ResourceSaver<class_ResourceSaver>`, :ref:`ResourceUID<class_ResourceUID>`, :ref:`TextServerManager<class_TextServerManager>`, :ref:`TileData<class_TileData>`, :ref:`Time<class_Time>`, :ref:`TranslationServer<class_TranslationServer>`, :ref:`TreeItem<class_TreeItem>`, :ref:`UndoRedo<class_UndoRedo>`, :ref:`VisualScriptCustomNodes<class_VisualScriptCustomNodes>`, :ref:`XRServer<class_XRServer>`
  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:`RefCounted<class_RefCounted>`, 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. .. tabs::
  19. .. code-tab:: gdscript
  20. var n = Node2D.new()
  21. print("position" in n) # Prints "true".
  22. print("other_property" in n) # Prints "false".
  23. .. code-tab:: csharp
  24. var node = new Node2D();
  25. // C# has no direct equivalent to GDScript's `in` operator here, but we
  26. // can achieve the same behavior by performing `Get` with a null check.
  27. GD.Print(node.Get("position") != null); // Prints "true".
  28. GD.Print(node.Get("other_property") != null); // Prints "false".
  29. The ``in`` operator will evaluate to ``true`` as long as the key exists, even if the value is ``null``.
  30. 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>`.
  31. **Note:** Unlike references to a :ref:`RefCounted<class_RefCounted>`, references to an Object stored in a variable can become invalid without warning. Therefore, it's recommended to use :ref:`RefCounted<class_RefCounted>` for data classes instead of ``Object``.
  32. Tutorials
  33. ---------
  34. - :doc:`When and how to avoid using nodes for everything <../tutorials/best_practices/node_alternatives>`
  35. Methods
  36. -------
  37. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Variant<class_Variant>` | :ref:`_get<class_Object_method__get>` **(** :ref:`StringName<class_StringName>` property **)** |virtual| |
  39. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Array<class_Array>` | :ref:`_get_property_list<class_Object_method__get_property_list>` **(** **)** |virtual| |
  41. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`_init<class_Object_method__init>` **(** **)** |virtual| |
  43. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | void | :ref:`_notification<class_Object_method__notification>` **(** :ref:`int<class_int>` what **)** |virtual| |
  45. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`bool<class_bool>` | :ref:`_set<class_Object_method__set>` **(** :ref:`StringName<class_StringName>` property, :ref:`Variant<class_Variant>` value **)** |virtual| |
  47. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`String<class_String>` | :ref:`_to_string<class_Object_method__to_string>` **(** **)** |virtual| |
  49. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`add_user_signal<class_Object_method_add_user_signal>` **(** :ref:`String<class_String>` signal, :ref:`Array<class_Array>` arguments=[] **)** |
  51. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Variant<class_Variant>` | :ref:`call<class_Object_method_call>` **(** :ref:`StringName<class_StringName>` method, ... **)** |vararg| |
  53. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | void | :ref:`call_deferred<class_Object_method_call_deferred>` **(** :ref:`StringName<class_StringName>` method, ... **)** |vararg| |
  55. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Variant<class_Variant>` | :ref:`callv<class_Object_method_callv>` **(** :ref:`StringName<class_StringName>` method, :ref:`Array<class_Array>` arg_array **)** |
  57. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`bool<class_bool>` | :ref:`can_translate_messages<class_Object_method_can_translate_messages>` **(** **)** |const| |
  59. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`connect<class_Object_method_connect>` **(** :ref:`StringName<class_StringName>` signal, :ref:`Callable<class_Callable>` callable, :ref:`Array<class_Array>` binds=[], :ref:`int<class_int>` flags=0 **)** |
  61. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`disconnect<class_Object_method_disconnect>` **(** :ref:`StringName<class_StringName>` signal, :ref:`Callable<class_Callable>` callable **)** |
  63. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`emit_signal<class_Object_method_emit_signal>` **(** :ref:`StringName<class_StringName>` signal, ... **)** |vararg| |
  65. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`free<class_Object_method_free>` **(** **)** |
  67. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`Variant<class_Variant>` | :ref:`get<class_Object_method_get>` **(** :ref:`String<class_String>` property **)** |const| |
  69. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`String<class_String>` | :ref:`get_class<class_Object_method_get_class>` **(** **)** |const| |
  71. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`Array<class_Array>` | :ref:`get_incoming_connections<class_Object_method_get_incoming_connections>` **(** **)** |const| |
  73. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`Variant<class_Variant>` | :ref:`get_indexed<class_Object_method_get_indexed>` **(** :ref:`NodePath<class_NodePath>` property **)** |const| |
  75. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`int<class_int>` | :ref:`get_instance_id<class_Object_method_get_instance_id>` **(** **)** |const| |
  77. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`Variant<class_Variant>` | :ref:`get_meta<class_Object_method_get_meta>` **(** :ref:`StringName<class_StringName>` name **)** |const| |
  79. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_meta_list<class_Object_method_get_meta_list>` **(** **)** |const| |
  81. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`Array<class_Array>` | :ref:`get_method_list<class_Object_method_get_method_list>` **(** **)** |const| |
  83. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`Array<class_Array>` | :ref:`get_property_list<class_Object_method_get_property_list>` **(** **)** |const| |
  85. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`Variant<class_Variant>` | :ref:`get_script<class_Object_method_get_script>` **(** **)** |const| |
  87. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`Array<class_Array>` | :ref:`get_signal_connection_list<class_Object_method_get_signal_connection_list>` **(** :ref:`String<class_String>` signal **)** |const| |
  89. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`Array<class_Array>` | :ref:`get_signal_list<class_Object_method_get_signal_list>` **(** **)** |const| |
  91. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`bool<class_bool>` | :ref:`has_meta<class_Object_method_has_meta>` **(** :ref:`StringName<class_StringName>` name **)** |const| |
  93. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`bool<class_bool>` | :ref:`has_method<class_Object_method_has_method>` **(** :ref:`StringName<class_StringName>` method **)** |const| |
  95. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`bool<class_bool>` | :ref:`has_signal<class_Object_method_has_signal>` **(** :ref:`StringName<class_StringName>` signal **)** |const| |
  97. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`bool<class_bool>` | :ref:`has_user_signal<class_Object_method_has_user_signal>` **(** :ref:`StringName<class_StringName>` signal **)** |const| |
  99. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`bool<class_bool>` | :ref:`is_blocking_signals<class_Object_method_is_blocking_signals>` **(** **)** |const| |
  101. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`bool<class_bool>` | :ref:`is_class<class_Object_method_is_class>` **(** :ref:`String<class_String>` class **)** |const| |
  103. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`bool<class_bool>` | :ref:`is_connected<class_Object_method_is_connected>` **(** :ref:`StringName<class_StringName>` signal, :ref:`Callable<class_Callable>` callable **)** |const| |
  105. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | :ref:`bool<class_bool>` | :ref:`is_queued_for_deletion<class_Object_method_is_queued_for_deletion>` **(** **)** |const| |
  107. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | void | :ref:`notification<class_Object_method_notification>` **(** :ref:`int<class_int>` what, :ref:`bool<class_bool>` reversed=false **)** |
  109. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | void | :ref:`notify_property_list_changed<class_Object_method_notify_property_list_changed>` **(** **)** |
  111. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | void | :ref:`remove_meta<class_Object_method_remove_meta>` **(** :ref:`StringName<class_StringName>` name **)** |
  113. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | void | :ref:`set<class_Object_method_set>` **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** |
  115. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | void | :ref:`set_block_signals<class_Object_method_set_block_signals>` **(** :ref:`bool<class_bool>` enable **)** |
  117. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | void | :ref:`set_deferred<class_Object_method_set_deferred>` **(** :ref:`StringName<class_StringName>` property, :ref:`Variant<class_Variant>` value **)** |
  119. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  120. | void | :ref:`set_indexed<class_Object_method_set_indexed>` **(** :ref:`NodePath<class_NodePath>` property, :ref:`Variant<class_Variant>` value **)** |
  121. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  122. | void | :ref:`set_message_translation<class_Object_method_set_message_translation>` **(** :ref:`bool<class_bool>` enable **)** |
  123. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  124. | void | :ref:`set_meta<class_Object_method_set_meta>` **(** :ref:`StringName<class_StringName>` name, :ref:`Variant<class_Variant>` value **)** |
  125. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  126. | void | :ref:`set_script<class_Object_method_set_script>` **(** :ref:`Variant<class_Variant>` script **)** |
  127. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  128. | :ref:`String<class_String>` | :ref:`to_string<class_Object_method_to_string>` **(** **)** |
  129. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  130. | :ref:`String<class_String>` | :ref:`tr<class_Object_method_tr>` **(** :ref:`StringName<class_StringName>` message, :ref:`StringName<class_StringName>` context="" **)** |const| |
  131. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  132. | :ref:`String<class_String>` | :ref:`tr_n<class_Object_method_tr_n>` **(** :ref:`StringName<class_StringName>` message, :ref:`StringName<class_StringName>` plural_message, :ref:`int<class_int>` n, :ref:`StringName<class_StringName>` context="" **)** |const| |
  133. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  134. Signals
  135. -------
  136. .. _class_Object_signal_property_list_changed:
  137. - **property_list_changed** **(** **)**
  138. ----
  139. .. _class_Object_signal_script_changed:
  140. - **script_changed** **(** **)**
  141. Emitted whenever the object's script is changed.
  142. Enumerations
  143. ------------
  144. .. _enum_Object_ConnectFlags:
  145. .. _class_Object_constant_CONNECT_DEFERRED:
  146. .. _class_Object_constant_CONNECT_PERSIST:
  147. .. _class_Object_constant_CONNECT_ONESHOT:
  148. .. _class_Object_constant_CONNECT_REFERENCE_COUNTED:
  149. enum **ConnectFlags**:
  150. - **CONNECT_DEFERRED** = **1** --- Connects a signal in deferred mode. This way, signal emissions are stored in a queue, then set on idle time.
  151. - **CONNECT_PERSIST** = **2** --- Persisting connections are saved when the object is serialized to file.
  152. - **CONNECT_ONESHOT** = **4** --- One-shot connections disconnect themselves after emission.
  153. - **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.
  154. Constants
  155. ---------
  156. .. _class_Object_constant_NOTIFICATION_POSTINITIALIZE:
  157. .. _class_Object_constant_NOTIFICATION_PREDELETE:
  158. - **NOTIFICATION_POSTINITIALIZE** = **0** --- Called right when the object is initialized. Not available in script.
  159. - **NOTIFICATION_PREDELETE** = **1** --- Called before the object is about to be deleted.
  160. Method Descriptions
  161. -------------------
  162. .. _class_Object_method__get:
  163. - :ref:`Variant<class_Variant>` **_get** **(** :ref:`StringName<class_StringName>` property **)** |virtual|
  164. Virtual method which can be overridden to customize the return value of :ref:`get<class_Object_method_get>`.
  165. Returns the given property. Returns ``null`` if the ``property`` does not exist.
  166. ----
  167. .. _class_Object_method__get_property_list:
  168. - :ref:`Array<class_Array>` **_get_property_list** **(** **)** |virtual|
  169. Virtual method which can be overridden to customize the return value of :ref:`get_property_list<class_Object_method_get_property_list>`.
  170. Returns the object's property list as an :ref:`Array<class_Array>` of dictionaries.
  171. 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>`).
  172. ----
  173. .. _class_Object_method__init:
  174. - void **_init** **(** **)** |virtual|
  175. Called when the object is initialized.
  176. ----
  177. .. _class_Object_method__notification:
  178. - void **_notification** **(** :ref:`int<class_int>` what **)** |virtual|
  179. 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.
  180. ----
  181. .. _class_Object_method__set:
  182. - :ref:`bool<class_bool>` **_set** **(** :ref:`StringName<class_StringName>` property, :ref:`Variant<class_Variant>` value **)** |virtual|
  183. Virtual method which can be overridden to customize the return value of :ref:`set<class_Object_method_set>`.
  184. Sets a property. Returns ``true`` if the ``property`` exists.
  185. ----
  186. .. _class_Object_method__to_string:
  187. - :ref:`String<class_String>` **_to_string** **(** **)** |virtual|
  188. 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)``.
  189. Returns a :ref:`String<class_String>` representing the object. If not overridden, defaults to ``"[ClassName:RID]"``.
  190. ----
  191. .. _class_Object_method_add_user_signal:
  192. - void **add_user_signal** **(** :ref:`String<class_String>` signal, :ref:`Array<class_Array>` arguments=[] **)**
  193. 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.
  194. ----
  195. .. _class_Object_method_call:
  196. - :ref:`Variant<class_Variant>` **call** **(** :ref:`StringName<class_StringName>` method, ... **)** |vararg|
  197. 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:
  198. .. tabs::
  199. .. code-tab:: gdscript
  200. var node = Node3D.new()
  201. node.call("rotate", Vector3(1.0, 0.0, 0.0), 1.571)
  202. .. code-tab:: csharp
  203. var node = new Node3D();
  204. node.Call("rotate", new Vector3(1f, 0f, 0f), 1.571f);
  205. **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).
  206. ----
  207. .. _class_Object_method_call_deferred:
  208. - void **call_deferred** **(** :ref:`StringName<class_StringName>` method, ... **)** |vararg|
  209. 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:
  210. .. tabs::
  211. .. code-tab:: gdscript
  212. var node = Node3D.new()
  213. node.call_deferred("rotate", Vector3(1.0, 0.0, 0.0), 1.571)
  214. .. code-tab:: csharp
  215. var node = new Node3D();
  216. node.CallDeferred("rotate", new Vector3(1f, 0f, 0f), 1.571f);
  217. **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).
  218. ----
  219. .. _class_Object_method_callv:
  220. - :ref:`Variant<class_Variant>` **callv** **(** :ref:`StringName<class_StringName>` method, :ref:`Array<class_Array>` arg_array **)**
  221. 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>`.
  222. .. tabs::
  223. .. code-tab:: gdscript
  224. var node = Node3D.new()
  225. node.callv("rotate", [Vector3(1.0, 0.0, 0.0), 1.571])
  226. .. code-tab:: csharp
  227. var node = new Node3D();
  228. node.Callv("rotate", new Godot.Collections.Array { new Vector3(1f, 0f, 0f), 1.571f });
  229. ----
  230. .. _class_Object_method_can_translate_messages:
  231. - :ref:`bool<class_bool>` **can_translate_messages** **(** **)** |const|
  232. 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>`.
  233. ----
  234. .. _class_Object_method_connect:
  235. - :ref:`Error<enum_@GlobalScope_Error>` **connect** **(** :ref:`StringName<class_StringName>` signal, :ref:`Callable<class_Callable>` callable, :ref:`Array<class_Array>` binds=[], :ref:`int<class_int>` flags=0 **)**
  236. Connects a ``signal`` to a ``callable``. Pass optional ``binds`` to the call as an :ref:`Array<class_Array>` of parameters. These parameters will be passed to the :ref:`Callable<class_Callable>`'s 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.
  237. **Note:** This method is the legacy implementation for connecting signals. The recommended modern approach is to use :ref:`Signal.connect<class_Signal_method_connect>` and to use :ref:`Callable.bind<class_Callable_method_bind>` to add and validate parameter binds. Both syntaxes are shown below.
  238. A signal can only be connected once to a :ref:`Callable<class_Callable>`. 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.
  239. If the callable's target is destroyed in the game's lifecycle, the connection will be lost.
  240. **Examples with recommended syntax:**
  241. Connecting signals is one of the most common operations in Godot and the API gives many options to do so, which are described further down. The code block below shows the recommended approach for both GDScript and C#.
  242. .. tabs::
  243. .. code-tab:: gdscript
  244. func _ready():
  245. var button = Button.new()
  246. # `button_down` here is a Signal object, and we thus call the Signal.connect() method,
  247. # not Object.connect(). See discussion below for a more in-depth overview of the API.
  248. button.button_down.connect(_on_button_down)
  249. # This assumes that a `Player` class exists which defines a `hit` signal.
  250. var player = Player.new()
  251. # We use Signal.connect() again, and we also use the Callable.bind() method which
  252. # returns a new Callable with the parameter binds.
  253. player.hit.connect(_on_player_hit.bind("sword", 100))
  254. func _on_button_down():
  255. print("Button down!")
  256. func _on_player_hit(weapon_type, damage):
  257. print("Hit with weapon %s for %d damage." % [weapon_type, damage])
  258. .. code-tab:: csharp
  259. public override void _Ready()
  260. {
  261. var button = new Button();
  262. // C# supports passing signals as events, so we can use this idiomatic construct:
  263. button.ButtonDown += OnButtonDown;
  264. // This assumes that a `Player` class exists which defines a `Hit` signal.
  265. var player = new Player();
  266. // Signals as events (`player.Hit += OnPlayerHit;`) do not support argument binding. You have to use:
  267. player.Hit.Connect(OnPlayerHit, new Godot.Collections.Array {"sword", 100 });
  268. }
  269. private void OnButtonDown()
  270. {
  271. GD.Print("Button down!");
  272. }
  273. private void OnPlayerHit(string weaponType, int damage)
  274. {
  275. GD.Print(String.Format("Hit with weapon {0} for {1} damage.", weaponType, damage));
  276. }
  277. **``Object.connect()`` or ``Signal.connect()``?**
  278. As seen above, the recommended method to connect signals is not :ref:`connect<class_Object_method_connect>`. The code block below shows the four options for connecting signals, using either this legacy method or the recommended :ref:`Signal.connect<class_Signal_method_connect>`, and using either an implicit :ref:`Callable<class_Callable>` or a manually defined one.
  279. .. tabs::
  280. .. code-tab:: gdscript
  281. func _ready():
  282. var button = Button.new()
  283. # Option 1: Object.connect() with an implicit Callable for the defined function.
  284. button.connect("button_down", _on_button_down)
  285. # Option 2: Object.connect() with a constructed Callable using a target object and method name.
  286. button.connect("button_down", Callable(self, "_on_button_down"))
  287. # Option 3: Signal.connect() with an implicit Callable for the defined function.
  288. button.button_down.connect(_on_button_down)
  289. # Option 4: Signal.connect() with a constructed Callable using a target object and method name.
  290. button.button_down.connect(Callable(self, "_on_button_down"))
  291. func _on_button_down():
  292. print("Button down!")
  293. .. code-tab:: csharp
  294. public override void _Ready()
  295. {
  296. var button = new Button();
  297. // Option 1: Object.Connect() with an implicit Callable for the defined function.
  298. button.Connect("button_down", OnButtonDown);
  299. // Option 2: Object.connect() with a constructed Callable using a target object and method name.
  300. button.Connect("button_down", new Callable(self, nameof(OnButtonDown)));
  301. // Option 3: Signal.connect() with an implicit Callable for the defined function.
  302. button.ButtonDown.Connect(OnButtonDown);
  303. // Option 3b: In C#, we can use signals as events and connect with this more idiomatic syntax:
  304. button.ButtonDown += OnButtonDown;
  305. // Option 4: Signal.connect() with a constructed Callable using a target object and method name.
  306. button.ButtonDown.Connect(new Callable(self, nameof(OnButtonDown)));
  307. }
  308. private void OnButtonDown()
  309. {
  310. GD.Print("Button down!");
  311. }
  312. While all options have the same outcome (``button``'s :ref:`BaseButton.button_down<class_BaseButton_signal_button_down>` signal will be connected to ``_on_button_down``), option 3 offers the best validation: it will throw a compile-time error if either the ``button_down`` signal or the ``_on_button_down`` callable are undefined. On the other hand, option 2 only relies on string names and will only be able to validate either names at runtime: it will throw a runtime error if ``"button_down"`` doesn't correspond to a signal, or if ``"_on_button_down"`` is not a registered method in the object ``self``. The main reason for using options 1, 2, or 4 would be if you actually need to use strings (e.g. to connect signals programmatically based on strings read from a configuration file). Otherwise, option 3 is the recommended (and fastest) method.
  313. **Parameter bindings and passing:**
  314. For legacy or language-specific reasons, there are also several ways to bind parameters to signals. One can pass a ``binds`` :ref:`Array<class_Array>` to :ref:`connect<class_Object_method_connect>` or :ref:`Signal.connect<class_Signal_method_connect>`, or use the recommended :ref:`Callable.bind<class_Callable_method_bind>` method to create a new callable from an existing one, with the given parameter binds.
  315. One can also pass additional parameters when emitting the signal with :ref:`emit_signal<class_Object_method_emit_signal>`. The examples below show the relationship between those two types of parameters.
  316. .. tabs::
  317. .. code-tab:: gdscript
  318. func _ready():
  319. # This assumes that a `Player` class exists which defines a `hit` signal.
  320. var player = Player.new()
  321. # Option 1: Using Callable.bind().
  322. player.hit.connect(_on_player_hit.bind("sword", 100))
  323. # Option 2: Using a `binds` Array in Signal.connect() (same syntax for Object.connect()).
  324. player.hit.connect(_on_player_hit, ["sword", 100])
  325. # Parameters added when emitting the signal are passed first.
  326. player.emit_signal("hit", "Dark lord", 5)
  327. # Four arguments, since we pass two when emitting (hit_by, level)
  328. # and two when connecting (weapon_type, damage).
  329. func _on_player_hit(hit_by, level, weapon_type, damage):
  330. print("Hit by %s (level %d) with weapon %s for %d damage." % [hit_by, level, weapon_type, damage])
  331. .. code-tab:: csharp
  332. public override void _Ready()
  333. {
  334. // This assumes that a `Player` class exists which defines a `Hit` signal.
  335. var player = new Player();
  336. // Option 1: Using Callable.Bind(). This way we can still use signals as events.
  337. player.Hit += OnPlayerHit.Bind("sword", 100);
  338. // Option 2: Using a `binds` Array in Signal.Connect() (same syntax for Object.Connect()).
  339. player.Hit.Connect(OnPlayerHit, new Godot.Collections.Array{ "sword", 100 });
  340. // Parameters added when emitting the signal are passed first.
  341. player.EmitSignal("hit", "Dark lord", 5);
  342. }
  343. // Four arguments, since we pass two when emitting (hitBy, level)
  344. // and two when connecting (weaponType, damage).
  345. private void OnPlayerHit(string hitBy, int level, string weaponType, int damage)
  346. {
  347. GD.Print(String.Format("Hit by {0} (level {1}) with weapon {2} for {3} damage.", hitBy, level, weaponType, damage));
  348. }
  349. ----
  350. .. _class_Object_method_disconnect:
  351. - void **disconnect** **(** :ref:`StringName<class_StringName>` signal, :ref:`Callable<class_Callable>` callable **)**
  352. Disconnects a ``signal`` from a given ``callable``.
  353. 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.
  354. ----
  355. .. _class_Object_method_emit_signal:
  356. - void **emit_signal** **(** :ref:`StringName<class_StringName>` signal, ... **)** |vararg|
  357. 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:
  358. .. tabs::
  359. .. code-tab:: gdscript
  360. emit_signal("hit", "sword", 100)
  361. emit_signal("game_over")
  362. .. code-tab:: csharp
  363. EmitSignal("hit", "sword", 100);
  364. EmitSignal("game_over");
  365. ----
  366. .. _class_Object_method_free:
  367. - void **free** **(** **)**
  368. 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``.
  369. ----
  370. .. _class_Object_method_get:
  371. - :ref:`Variant<class_Variant>` **get** **(** :ref:`String<class_String>` property **)** |const|
  372. Returns the :ref:`Variant<class_Variant>` value of the given ``property``. If the ``property`` doesn't exist, this will return ``null``.
  373. **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).
  374. ----
  375. .. _class_Object_method_get_class:
  376. - :ref:`String<class_String>` **get_class** **(** **)** |const|
  377. Returns the object's class as a :ref:`String<class_String>`. See also :ref:`is_class<class_Object_method_is_class>`.
  378. **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.
  379. ----
  380. .. _class_Object_method_get_incoming_connections:
  381. - :ref:`Array<class_Array>` **get_incoming_connections** **(** **)** |const|
  382. Returns an :ref:`Array<class_Array>` of dictionaries with information about signals that are connected to the object.
  383. Each :ref:`Dictionary<class_Dictionary>` contains three String entries:
  384. - ``source`` is a reference to the signal emitter.
  385. - ``signal_name`` is the name of the connected signal.
  386. - ``method_name`` is the name of the method to which the signal is connected.
  387. ----
  388. .. _class_Object_method_get_indexed:
  389. - :ref:`Variant<class_Variant>` **get_indexed** **(** :ref:`NodePath<class_NodePath>` property **)** |const|
  390. 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"``.
  391. ----
  392. .. _class_Object_method_get_instance_id:
  393. - :ref:`int<class_int>` **get_instance_id** **(** **)** |const|
  394. Returns the object's unique instance ID.
  395. This ID can be saved in :ref:`EncodedObjectAsID<class_EncodedObjectAsID>`, and can be used to retrieve the object instance with :ref:`@GlobalScope.instance_from_id<class_@GlobalScope_method_instance_from_id>`.
  396. ----
  397. .. _class_Object_method_get_meta:
  398. - :ref:`Variant<class_Variant>` **get_meta** **(** :ref:`StringName<class_StringName>` name **)** |const|
  399. Returns the object's metadata entry for the given ``name``.
  400. ----
  401. .. _class_Object_method_get_meta_list:
  402. - :ref:`PackedStringArray<class_PackedStringArray>` **get_meta_list** **(** **)** |const|
  403. Returns the object's metadata as a :ref:`PackedStringArray<class_PackedStringArray>`.
  404. ----
  405. .. _class_Object_method_get_method_list:
  406. - :ref:`Array<class_Array>` **get_method_list** **(** **)** |const|
  407. Returns the object's methods and their signatures as an :ref:`Array<class_Array>`.
  408. ----
  409. .. _class_Object_method_get_property_list:
  410. - :ref:`Array<class_Array>` **get_property_list** **(** **)** |const|
  411. Returns the object's property list as an :ref:`Array<class_Array>` of dictionaries.
  412. 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>`).
  413. ----
  414. .. _class_Object_method_get_script:
  415. - :ref:`Variant<class_Variant>` **get_script** **(** **)** |const|
  416. Returns the object's :ref:`Script<class_Script>` instance, or ``null`` if none is assigned.
  417. ----
  418. .. _class_Object_method_get_signal_connection_list:
  419. - :ref:`Array<class_Array>` **get_signal_connection_list** **(** :ref:`String<class_String>` signal **)** |const|
  420. Returns an :ref:`Array<class_Array>` of connections for the given ``signal``.
  421. ----
  422. .. _class_Object_method_get_signal_list:
  423. - :ref:`Array<class_Array>` **get_signal_list** **(** **)** |const|
  424. Returns the list of signals as an :ref:`Array<class_Array>` of dictionaries.
  425. ----
  426. .. _class_Object_method_has_meta:
  427. - :ref:`bool<class_bool>` **has_meta** **(** :ref:`StringName<class_StringName>` name **)** |const|
  428. Returns ``true`` if a metadata entry is found with the given ``name``.
  429. ----
  430. .. _class_Object_method_has_method:
  431. - :ref:`bool<class_bool>` **has_method** **(** :ref:`StringName<class_StringName>` method **)** |const|
  432. Returns ``true`` if the object contains the given ``method``.
  433. ----
  434. .. _class_Object_method_has_signal:
  435. - :ref:`bool<class_bool>` **has_signal** **(** :ref:`StringName<class_StringName>` signal **)** |const|
  436. Returns ``true`` if the given ``signal`` exists.
  437. ----
  438. .. _class_Object_method_has_user_signal:
  439. - :ref:`bool<class_bool>` **has_user_signal** **(** :ref:`StringName<class_StringName>` signal **)** |const|
  440. 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.
  441. ----
  442. .. _class_Object_method_is_blocking_signals:
  443. - :ref:`bool<class_bool>` **is_blocking_signals** **(** **)** |const|
  444. Returns ``true`` if signal emission blocking is enabled.
  445. ----
  446. .. _class_Object_method_is_class:
  447. - :ref:`bool<class_bool>` **is_class** **(** :ref:`String<class_String>` class **)** |const|
  448. Returns ``true`` if the object inherits from the given ``class``. See also :ref:`get_class<class_Object_method_get_class>`.
  449. **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.
  450. ----
  451. .. _class_Object_method_is_connected:
  452. - :ref:`bool<class_bool>` **is_connected** **(** :ref:`StringName<class_StringName>` signal, :ref:`Callable<class_Callable>` callable **)** |const|
  453. Returns ``true`` if a connection exists for a given ``signal`` and ``callable``.
  454. ----
  455. .. _class_Object_method_is_queued_for_deletion:
  456. - :ref:`bool<class_bool>` **is_queued_for_deletion** **(** **)** |const|
  457. Returns ``true`` if the :ref:`Node.queue_free<class_Node_method_queue_free>` method was called for the object.
  458. ----
  459. .. _class_Object_method_notification:
  460. - void **notification** **(** :ref:`int<class_int>` what, :ref:`bool<class_bool>` reversed=false **)**
  461. 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.
  462. 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.
  463. ----
  464. .. _class_Object_method_notify_property_list_changed:
  465. - void **notify_property_list_changed** **(** **)**
  466. Notify the editor that the property list has changed by emitting the :ref:`property_list_changed<class_Object_signal_property_list_changed>` signal, so that editor plugins can take the new values into account.
  467. ----
  468. .. _class_Object_method_remove_meta:
  469. - void **remove_meta** **(** :ref:`StringName<class_StringName>` name **)**
  470. Removes a given entry from the object's metadata. See also :ref:`set_meta<class_Object_method_set_meta>`.
  471. ----
  472. .. _class_Object_method_set:
  473. - void **set** **(** :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)**
  474. Assigns a new value to the given property. If the ``property`` does not exist, nothing will happen.
  475. **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).
  476. ----
  477. .. _class_Object_method_set_block_signals:
  478. - void **set_block_signals** **(** :ref:`bool<class_bool>` enable **)**
  479. If set to ``true``, signal emission is blocked.
  480. ----
  481. .. _class_Object_method_set_deferred:
  482. - void **set_deferred** **(** :ref:`StringName<class_StringName>` property, :ref:`Variant<class_Variant>` value **)**
  483. 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)``.
  484. **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).
  485. ----
  486. .. _class_Object_method_set_indexed:
  487. - void **set_indexed** **(** :ref:`NodePath<class_NodePath>` property, :ref:`Variant<class_Variant>` value **)**
  488. 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:
  489. .. tabs::
  490. .. code-tab:: gdscript
  491. var node = Node2D.new()
  492. node.set_indexed("position", Vector2(42, 0))
  493. node.set_indexed("position:y", -10)
  494. print(node.position) # (42, -10)
  495. .. code-tab:: csharp
  496. var node = new Node2D();
  497. node.SetIndexed("position", new Vector2(42, 0));
  498. node.SetIndexed("position:y", -10);
  499. GD.Print(node.Position); // (42, -10)
  500. ----
  501. .. _class_Object_method_set_message_translation:
  502. - void **set_message_translation** **(** :ref:`bool<class_bool>` enable **)**
  503. Defines whether the object can translate strings (with calls to :ref:`tr<class_Object_method_tr>`). Enabled by default.
  504. ----
  505. .. _class_Object_method_set_meta:
  506. - void **set_meta** **(** :ref:`StringName<class_StringName>` name, :ref:`Variant<class_Variant>` value **)**
  507. Adds, changes or removes a given entry in the object's metadata. Metadata are serialized and can take any :ref:`Variant<class_Variant>` value.
  508. 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"``.
  509. ----
  510. .. _class_Object_method_set_script:
  511. - void **set_script** **(** :ref:`Variant<class_Variant>` script **)**
  512. Assigns a script to the object. Each object can have a single script assigned to it, which are used to extend its functionality.
  513. 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.
  514. ----
  515. .. _class_Object_method_to_string:
  516. - :ref:`String<class_String>` **to_string** **(** **)**
  517. Returns a :ref:`String<class_String>` representing the object. If not overridden, defaults to ``"[ClassName:RID]"``.
  518. Override the method :ref:`_to_string<class_Object_method__to_string>` to customize the :ref:`String<class_String>` representation.
  519. ----
  520. .. _class_Object_method_tr:
  521. - :ref:`String<class_String>` **tr** **(** :ref:`StringName<class_StringName>` message, :ref:`StringName<class_StringName>` context="" **)** |const|
  522. Translates a message using translation catalogs configured in the Project Settings. An additional context could be used to specify the translation context.
  523. 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>`.
  524. See :doc:`Internationalizing games <../tutorials/i18n/internationalizing_games>` for examples of the usage of this method.
  525. ----
  526. .. _class_Object_method_tr_n:
  527. - :ref:`String<class_String>` **tr_n** **(** :ref:`StringName<class_StringName>` message, :ref:`StringName<class_StringName>` plural_message, :ref:`int<class_int>` n, :ref:`StringName<class_StringName>` context="" **)** |const|
  528. Translates a message involving plurals using translation catalogs configured in the Project Settings. An additional context could be used to specify the translation context.
  529. Only works if message translation is enabled (which it is by default), otherwise it returns the ``message`` or ``plural_message`` unchanged. See :ref:`set_message_translation<class_Object_method_set_message_translation>`.
  530. The number ``n`` is the number or quantity of the plural object. It will be used to guide the translation system to fetch the correct plural form for the selected language.
  531. **Note:** Negative and floating-point values usually represent physical entities for which singular and plural don't clearly apply. In such cases, use :ref:`tr<class_Object_method_tr>`.
  532. See :doc:`Localization using gettext <../tutorials/i18n/localization_using_gettext>` for examples of the usage of this method.
  533. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  534. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  535. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  536. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  537. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  538. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`