class_object.rst 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  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/4.2/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/Object.xml.
  6. .. _class_Object:
  7. Object
  8. ======
  9. **Inherited By:** :ref:`AudioServer<class_AudioServer>`, :ref:`CameraServer<class_CameraServer>`, :ref:`ClassDB<class_ClassDB>`, :ref:`DisplayServer<class_DisplayServer>`, :ref:`EditorFileSystemDirectory<class_EditorFileSystemDirectory>`, :ref:`EditorInterface<class_EditorInterface>`, :ref:`EditorPaths<class_EditorPaths>`, :ref:`EditorSelection<class_EditorSelection>`, :ref:`EditorUndoRedoManager<class_EditorUndoRedoManager>`, :ref:`EditorVCSInterface<class_EditorVCSInterface>`, :ref:`Engine<class_Engine>`, :ref:`EngineDebugger<class_EngineDebugger>`, :ref:`GDExtensionManager<class_GDExtensionManager>`, :ref:`Geometry2D<class_Geometry2D>`, :ref:`Geometry3D<class_Geometry3D>`, :ref:`GodotSharp<class_GodotSharp>`, :ref:`Input<class_Input>`, :ref:`InputMap<class_InputMap>`, :ref:`IP<class_IP>`, :ref:`JavaClassWrapper<class_JavaClassWrapper>`, :ref:`JavaScriptBridge<class_JavaScriptBridge>`, :ref:`JNISingleton<class_JNISingleton>`, :ref:`JSONRPC<class_JSONRPC>`, :ref:`MainLoop<class_MainLoop>`, :ref:`Marshalls<class_Marshalls>`, :ref:`MovieWriter<class_MovieWriter>`, :ref:`NavigationMeshGenerator<class_NavigationMeshGenerator>`, :ref:`NavigationServer2D<class_NavigationServer2D>`, :ref:`NavigationServer3D<class_NavigationServer3D>`, :ref:`Node<class_Node>`, :ref:`OpenXRExtensionWrapperExtension<class_OpenXRExtensionWrapperExtension>`, :ref:`OpenXRInteractionProfileMetadata<class_OpenXRInteractionProfileMetadata>`, :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:`PhysicsServer2DManager<class_PhysicsServer2DManager>`, :ref:`PhysicsServer3D<class_PhysicsServer3D>`, :ref:`PhysicsServer3DManager<class_PhysicsServer3DManager>`, :ref:`PhysicsServer3DRenderingServerHandler<class_PhysicsServer3DRenderingServerHandler>`, :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:`ScriptLanguage<class_ScriptLanguage>`, :ref:`TextServerManager<class_TextServerManager>`, :ref:`ThemeDB<class_ThemeDB>`, :ref:`TileData<class_TileData>`, :ref:`Time<class_Time>`, :ref:`TranslationServer<class_TranslationServer>`, :ref:`TreeItem<class_TreeItem>`, :ref:`UndoRedo<class_UndoRedo>`, :ref:`WorkerThreadPool<class_WorkerThreadPool>`, :ref:`XRServer<class_XRServer>`
  10. Base class for all other classes in the engine.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. An advanced :ref:`Variant<class_Variant>` type. All classes in the engine inherit from Object. Each class may define new properties, methods or signals, which are available to all inheriting classes. For example, a :ref:`Sprite2D<class_Sprite2D>` instance is able to call :ref:`Node.add_child<class_Node_method_add_child>` because it inherits from :ref:`Node<class_Node>`.
  15. You can create new instances, using ``Object.new()`` in GDScript, or ``new GodotObject`` in C#.
  16. To delete an Object instance, call :ref:`free<class_Object_method_free>`. This is necessary for most classes inheriting Object, because they do not manage memory on their own, and will otherwise cause memory leaks when no longer in use. There are a few classes that perform memory management. For example, :ref:`RefCounted<class_RefCounted>` (and by extension :ref:`Resource<class_Resource>`) deletes itself when no longer referenced, and :ref:`Node<class_Node>` deletes its children when freed.
  17. Objects can have a :ref:`Script<class_Script>` attached to them. Once the :ref:`Script<class_Script>` is instantiated, it effectively acts as an extension to the base class, allowing it to define and inherit new properties, methods and signals.
  18. Inside a :ref:`Script<class_Script>`, :ref:`_get_property_list<class_Object_private_method__get_property_list>` may be overridden to customize properties in several ways. This allows them to be available to the editor, display as lists of options, sub-divide into groups, save on disk, etc. Scripting languages offer easier ways to customize properties, such as with the :ref:`@GDScript.@export<class_@GDScript_annotation_@export>` annotation.
  19. Godot is very dynamic. An object's script, and therefore its properties, methods and signals, can be changed at run-time. Because of this, there can be occasions where, for example, a property required by a method may not exist. To prevent run-time errors, see methods such as :ref:`set<class_Object_method_set>`, :ref:`get<class_Object_method_get>`, :ref:`call<class_Object_method_call>`, :ref:`has_method<class_Object_method_has_method>`, :ref:`has_signal<class_Object_method_has_signal>`, etc. Note that these methods are **much** slower than direct references.
  20. In GDScript, you can also check if a given property, method, or signal name exists in an object with the ``in`` operator:
  21. ::
  22. var node = Node.new()
  23. print("name" in node) # Prints true
  24. print("get_parent" in node) # Prints true
  25. print("tree_entered" in node) # Prints true
  26. print("unknown" in node) # Prints false
  27. Notifications are :ref:`int<class_int>` constants commonly sent and received by objects. For example, on every rendered frame, the :ref:`SceneTree<class_SceneTree>` notifies nodes inside the tree with a :ref:`Node.NOTIFICATION_PROCESS<class_Node_constant_NOTIFICATION_PROCESS>`. The nodes receive it and may call :ref:`Node._process<class_Node_private_method__process>` to update. To make use of notifications, see :ref:`notification<class_Object_method_notification>` and :ref:`_notification<class_Object_private_method__notification>`.
  28. Lastly, every object can also contain metadata (data about data). :ref:`set_meta<class_Object_method_set_meta>` can be useful to store information that the object itself does not depend on. To keep your code clean, making excessive use of metadata is discouraged.
  29. \ **Note:** Unlike references to a :ref:`RefCounted<class_RefCounted>`, references to an object stored in a variable can become invalid without being set to ``null``. To check if an object has been deleted, do *not* compare it against ``null``. Instead, use :ref:`@GlobalScope.is_instance_valid<class_@GlobalScope_method_is_instance_valid>`. It's also recommended to inherit from :ref:`RefCounted<class_RefCounted>` for classes storing data instead of **Object**.
  30. \ **Note:** The ``script`` is not exposed like most properties. To set or get an object's :ref:`Script<class_Script>` in code, use :ref:`set_script<class_Object_method_set_script>` and :ref:`get_script<class_Object_method_get_script>`, respectively.
  31. .. rst-class:: classref-introduction-group
  32. Tutorials
  33. ---------
  34. - :doc:`Object class introduction <../contributing/development/core_and_modules/object_class>`
  35. - :doc:`When and how to avoid using nodes for everything <../tutorials/best_practices/node_alternatives>`
  36. - :doc:`Object notifications <../tutorials/best_practices/godot_notifications>`
  37. .. rst-class:: classref-reftable-group
  38. Methods
  39. -------
  40. .. table::
  41. :widths: auto
  42. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Variant<class_Variant>` | :ref:`_get<class_Object_private_method__get>` **(** :ref:`StringName<class_StringName>` property **)** |virtual| |
  44. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Dictionary[]<class_Dictionary>` | :ref:`_get_property_list<class_Object_private_method__get_property_list>` **(** **)** |virtual| |
  46. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`_init<class_Object_private_method__init>` **(** **)** |virtual| |
  48. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`_notification<class_Object_private_method__notification>` **(** :ref:`int<class_int>` what **)** |virtual| |
  50. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`bool<class_bool>` | :ref:`_property_can_revert<class_Object_private_method__property_can_revert>` **(** :ref:`StringName<class_StringName>` property **)** |virtual| |
  52. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`Variant<class_Variant>` | :ref:`_property_get_revert<class_Object_private_method__property_get_revert>` **(** :ref:`StringName<class_StringName>` property **)** |virtual| |
  54. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`bool<class_bool>` | :ref:`_set<class_Object_private_method__set>` **(** :ref:`StringName<class_StringName>` property, :ref:`Variant<class_Variant>` value **)** |virtual| |
  56. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`String<class_String>` | :ref:`_to_string<class_Object_private_method__to_string>` **(** **)** |virtual| |
  58. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`_validate_property<class_Object_private_method__validate_property>` **(** :ref:`Dictionary<class_Dictionary>` property **)** |virtual| |
  60. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`add_user_signal<class_Object_method_add_user_signal>` **(** :ref:`String<class_String>` signal, :ref:`Array<class_Array>` arguments=[] **)** |
  62. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`Variant<class_Variant>` | :ref:`call<class_Object_method_call>` **(** :ref:`StringName<class_StringName>` method, ... **)** |vararg| |
  64. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Variant<class_Variant>` | :ref:`call_deferred<class_Object_method_call_deferred>` **(** :ref:`StringName<class_StringName>` method, ... **)** |vararg| |
  66. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`Variant<class_Variant>` | :ref:`callv<class_Object_method_callv>` **(** :ref:`StringName<class_StringName>` method, :ref:`Array<class_Array>` arg_array **)** |
  68. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`bool<class_bool>` | :ref:`can_translate_messages<class_Object_method_can_translate_messages>` **(** **)** |const| |
  70. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`cancel_free<class_Object_method_cancel_free>` **(** **)** |
  72. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`connect<class_Object_method_connect>` **(** :ref:`StringName<class_StringName>` signal, :ref:`Callable<class_Callable>` callable, :ref:`int<class_int>` flags=0 **)** |
  74. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`disconnect<class_Object_method_disconnect>` **(** :ref:`StringName<class_StringName>` signal, :ref:`Callable<class_Callable>` callable **)** |
  76. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`emit_signal<class_Object_method_emit_signal>` **(** :ref:`StringName<class_StringName>` signal, ... **)** |vararg| |
  78. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`free<class_Object_method_free>` **(** **)** |
  80. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`Variant<class_Variant>` | :ref:`get<class_Object_method_get>` **(** :ref:`StringName<class_StringName>` property **)** |const| |
  82. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`String<class_String>` | :ref:`get_class<class_Object_method_get_class>` **(** **)** |const| |
  84. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | :ref:`Dictionary[]<class_Dictionary>` | :ref:`get_incoming_connections<class_Object_method_get_incoming_connections>` **(** **)** |const| |
  86. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | :ref:`Variant<class_Variant>` | :ref:`get_indexed<class_Object_method_get_indexed>` **(** :ref:`NodePath<class_NodePath>` property_path **)** |const| |
  88. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | :ref:`int<class_int>` | :ref:`get_instance_id<class_Object_method_get_instance_id>` **(** **)** |const| |
  90. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`Variant<class_Variant>` | :ref:`get_meta<class_Object_method_get_meta>` **(** :ref:`StringName<class_StringName>` name, :ref:`Variant<class_Variant>` default=null **)** |const| |
  92. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`StringName[]<class_StringName>` | :ref:`get_meta_list<class_Object_method_get_meta_list>` **(** **)** |const| |
  94. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`Dictionary[]<class_Dictionary>` | :ref:`get_method_list<class_Object_method_get_method_list>` **(** **)** |const| |
  96. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :ref:`Dictionary[]<class_Dictionary>` | :ref:`get_property_list<class_Object_method_get_property_list>` **(** **)** |const| |
  98. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | :ref:`Variant<class_Variant>` | :ref:`get_script<class_Object_method_get_script>` **(** **)** |const| |
  100. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | :ref:`Dictionary[]<class_Dictionary>` | :ref:`get_signal_connection_list<class_Object_method_get_signal_connection_list>` **(** :ref:`StringName<class_StringName>` signal **)** |const| |
  102. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | :ref:`Dictionary[]<class_Dictionary>` | :ref:`get_signal_list<class_Object_method_get_signal_list>` **(** **)** |const| |
  104. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | :ref:`bool<class_bool>` | :ref:`has_meta<class_Object_method_has_meta>` **(** :ref:`StringName<class_StringName>` name **)** |const| |
  106. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | :ref:`bool<class_bool>` | :ref:`has_method<class_Object_method_has_method>` **(** :ref:`StringName<class_StringName>` method **)** |const| |
  108. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. | :ref:`bool<class_bool>` | :ref:`has_signal<class_Object_method_has_signal>` **(** :ref:`StringName<class_StringName>` signal **)** |const| |
  110. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  111. | :ref:`bool<class_bool>` | :ref:`has_user_signal<class_Object_method_has_user_signal>` **(** :ref:`StringName<class_StringName>` signal **)** |const| |
  112. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  113. | :ref:`bool<class_bool>` | :ref:`is_blocking_signals<class_Object_method_is_blocking_signals>` **(** **)** |const| |
  114. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  115. | :ref:`bool<class_bool>` | :ref:`is_class<class_Object_method_is_class>` **(** :ref:`String<class_String>` class **)** |const| |
  116. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  117. | :ref:`bool<class_bool>` | :ref:`is_connected<class_Object_method_is_connected>` **(** :ref:`StringName<class_StringName>` signal, :ref:`Callable<class_Callable>` callable **)** |const| |
  118. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  119. | :ref:`bool<class_bool>` | :ref:`is_queued_for_deletion<class_Object_method_is_queued_for_deletion>` **(** **)** |const| |
  120. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  121. | void | :ref:`notification<class_Object_method_notification>` **(** :ref:`int<class_int>` what, :ref:`bool<class_bool>` reversed=false **)** |
  122. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  123. | void | :ref:`notify_property_list_changed<class_Object_method_notify_property_list_changed>` **(** **)** |
  124. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  125. | :ref:`bool<class_bool>` | :ref:`property_can_revert<class_Object_method_property_can_revert>` **(** :ref:`StringName<class_StringName>` property **)** |const| |
  126. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  127. | :ref:`Variant<class_Variant>` | :ref:`property_get_revert<class_Object_method_property_get_revert>` **(** :ref:`StringName<class_StringName>` property **)** |const| |
  128. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  129. | void | :ref:`remove_meta<class_Object_method_remove_meta>` **(** :ref:`StringName<class_StringName>` name **)** |
  130. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  131. | void | :ref:`set<class_Object_method_set>` **(** :ref:`StringName<class_StringName>` property, :ref:`Variant<class_Variant>` value **)** |
  132. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  133. | void | :ref:`set_block_signals<class_Object_method_set_block_signals>` **(** :ref:`bool<class_bool>` enable **)** |
  134. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  135. | void | :ref:`set_deferred<class_Object_method_set_deferred>` **(** :ref:`StringName<class_StringName>` property, :ref:`Variant<class_Variant>` value **)** |
  136. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  137. | void | :ref:`set_indexed<class_Object_method_set_indexed>` **(** :ref:`NodePath<class_NodePath>` property_path, :ref:`Variant<class_Variant>` value **)** |
  138. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  139. | void | :ref:`set_message_translation<class_Object_method_set_message_translation>` **(** :ref:`bool<class_bool>` enable **)** |
  140. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  141. | void | :ref:`set_meta<class_Object_method_set_meta>` **(** :ref:`StringName<class_StringName>` name, :ref:`Variant<class_Variant>` value **)** |
  142. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  143. | void | :ref:`set_script<class_Object_method_set_script>` **(** :ref:`Variant<class_Variant>` script **)** |
  144. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  145. | :ref:`String<class_String>` | :ref:`to_string<class_Object_method_to_string>` **(** **)** |
  146. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  147. | :ref:`String<class_String>` | :ref:`tr<class_Object_method_tr>` **(** :ref:`StringName<class_StringName>` message, :ref:`StringName<class_StringName>` context="" **)** |const| |
  148. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  149. | :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| |
  150. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  151. .. rst-class:: classref-section-separator
  152. ----
  153. .. rst-class:: classref-descriptions-group
  154. Signals
  155. -------
  156. .. _class_Object_signal_property_list_changed:
  157. .. rst-class:: classref-signal
  158. **property_list_changed** **(** **)**
  159. Emitted when :ref:`notify_property_list_changed<class_Object_method_notify_property_list_changed>` is called.
  160. .. rst-class:: classref-item-separator
  161. ----
  162. .. _class_Object_signal_script_changed:
  163. .. rst-class:: classref-signal
  164. **script_changed** **(** **)**
  165. Emitted when the object's script is changed.
  166. \ **Note:** When this signal is emitted, the new script is not initialized yet. If you need to access the new script, defer connections to this signal with :ref:`CONNECT_DEFERRED<class_Object_constant_CONNECT_DEFERRED>`.
  167. .. rst-class:: classref-section-separator
  168. ----
  169. .. rst-class:: classref-descriptions-group
  170. Enumerations
  171. ------------
  172. .. _enum_Object_ConnectFlags:
  173. .. rst-class:: classref-enumeration
  174. enum **ConnectFlags**:
  175. .. _class_Object_constant_CONNECT_DEFERRED:
  176. .. rst-class:: classref-enumeration-constant
  177. :ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_DEFERRED** = ``1``
  178. Deferred connections trigger their :ref:`Callable<class_Callable>`\ s on idle time (at the end of the frame), rather than instantly.
  179. .. _class_Object_constant_CONNECT_PERSIST:
  180. .. rst-class:: classref-enumeration-constant
  181. :ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_PERSIST** = ``2``
  182. Persisting connections are stored when the object is serialized (such as when using :ref:`PackedScene.pack<class_PackedScene_method_pack>`). In the editor, connections created through the Node dock are always persisting.
  183. .. _class_Object_constant_CONNECT_ONE_SHOT:
  184. .. rst-class:: classref-enumeration-constant
  185. :ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_ONE_SHOT** = ``4``
  186. One-shot connections disconnect themselves after emission.
  187. .. _class_Object_constant_CONNECT_REFERENCE_COUNTED:
  188. .. rst-class:: classref-enumeration-constant
  189. :ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_REFERENCE_COUNTED** = ``8``
  190. Reference-counted connections can be assigned to the same :ref:`Callable<class_Callable>` multiple times. Each disconnection decreases the internal counter. The signal fully disconnects only when the counter reaches 0.
  191. .. rst-class:: classref-section-separator
  192. ----
  193. .. rst-class:: classref-descriptions-group
  194. Constants
  195. ---------
  196. .. _class_Object_constant_NOTIFICATION_POSTINITIALIZE:
  197. .. rst-class:: classref-constant
  198. **NOTIFICATION_POSTINITIALIZE** = ``0``
  199. Notification received when the object is initialized, before its script is attached. Used internally.
  200. .. _class_Object_constant_NOTIFICATION_PREDELETE:
  201. .. rst-class:: classref-constant
  202. **NOTIFICATION_PREDELETE** = ``1``
  203. Notification received when the object is about to be deleted. Can act as the deconstructor of some programming languages.
  204. .. _class_Object_constant_NOTIFICATION_EXTENSION_RELOADED:
  205. .. rst-class:: classref-constant
  206. **NOTIFICATION_EXTENSION_RELOADED** = ``2``
  207. Notification received when the object finishes hot reloading. This notification is only sent for extensions classes and derived.
  208. .. rst-class:: classref-section-separator
  209. ----
  210. .. rst-class:: classref-descriptions-group
  211. Method Descriptions
  212. -------------------
  213. .. _class_Object_private_method__get:
  214. .. rst-class:: classref-method
  215. :ref:`Variant<class_Variant>` **_get** **(** :ref:`StringName<class_StringName>` property **)** |virtual|
  216. Override this method to customize the behavior of :ref:`get<class_Object_method_get>`. Should return the given ``property``'s value, or ``null`` if the ``property`` should be handled normally.
  217. Combined with :ref:`_set<class_Object_private_method__set>` and :ref:`_get_property_list<class_Object_private_method__get_property_list>`, this method allows defining custom properties, which is particularly useful for editor plugins. Note that a property must be present in :ref:`get_property_list<class_Object_method_get_property_list>`, otherwise this method will not be called.
  218. .. tabs::
  219. .. code-tab:: gdscript
  220. func _get(property):
  221. if property == "fake_property":
  222. print("Getting my property!")
  223. return 4
  224. func _get_property_list():
  225. return [
  226. { "name": "fake_property", "type": TYPE_INT }
  227. ]
  228. .. code-tab:: csharp
  229. public override Variant _Get(StringName property)
  230. {
  231. if (property == "FakeProperty")
  232. {
  233. GD.Print("Getting my property!");
  234. return 4;
  235. }
  236. return default;
  237. }
  238. public override Godot.Collections.Array<Godot.Collections.Dictionary> _GetPropertyList()
  239. {
  240. return new Godot.Collections.Array<Godot.Collections.Dictionary>()
  241. {
  242. new Godot.Collections.Dictionary()
  243. {
  244. { "name", "FakeProperty" },
  245. { "type", (int)Variant.Type.Int }
  246. }
  247. };
  248. }
  249. .. rst-class:: classref-item-separator
  250. ----
  251. .. _class_Object_private_method__get_property_list:
  252. .. rst-class:: classref-method
  253. :ref:`Dictionary[]<class_Dictionary>` **_get_property_list** **(** **)** |virtual|
  254. Override this method to customize how script properties should be handled by the engine.
  255. Should return a property list, as an :ref:`Array<class_Array>` of dictionaries. The result is added to the array of :ref:`get_property_list<class_Object_method_get_property_list>`, and should be formatted in the same way. Each :ref:`Dictionary<class_Dictionary>` must at least contain the ``name`` and ``type`` entries.
  256. The example below displays ``hammer_type`` in the Inspector dock, only if ``holding_hammer`` is ``true``:
  257. .. tabs::
  258. .. code-tab:: gdscript
  259. @tool
  260. extends Node2D
  261. @export var holding_hammer = false:
  262. set(value):
  263. holding_hammer = value
  264. notify_property_list_changed()
  265. var hammer_type = 0
  266. func _get_property_list():
  267. # By default, `hammer_type` is not visible in the editor.
  268. var property_usage = PROPERTY_USAGE_NO_EDITOR
  269. if holding_hammer:
  270. property_usage = PROPERTY_USAGE_DEFAULT
  271. var properties = []
  272. properties.append({
  273. "name": "hammer_type",
  274. "type": TYPE_INT,
  275. "usage": property_usage, # See above assignment.
  276. "hint": PROPERTY_HINT_ENUM,
  277. "hint_string": "Wooden,Iron,Golden,Enchanted"
  278. })
  279. return properties
  280. .. code-tab:: csharp
  281. [Tool]
  282. public partial class MyNode2D : Node2D
  283. {
  284. private bool _holdingHammer;
  285. [Export]
  286. public bool HoldingHammer
  287. {
  288. get => _holdingHammer;
  289. set
  290. {
  291. _holdingHammer = value;
  292. NotifyPropertyListChanged();
  293. }
  294. }
  295. public int HammerType { get; set; }
  296. public override Godot.Collections.Array<Godot.Collections.Dictionary> _GetPropertyList()
  297. {
  298. // By default, `HammerType` is not visible in the editor.
  299. var propertyUsage = PropertyUsageFlags.NoEditor;
  300. if (HoldingHammer)
  301. {
  302. propertyUsage = PropertyUsageFlags.Default;
  303. }
  304. var properties = new Godot.Collections.Array<Godot.Collections.Dictionary>();
  305. properties.Add(new Godot.Collections.Dictionary()
  306. {
  307. { "name", "HammerType" },
  308. { "type", (int)Variant.Type.Int },
  309. { "usage", (int)propertyUsage }, // See above assignment.
  310. { "hint", (int)PropertyHint.Enum },
  311. { "hint_string", "Wooden,Iron,Golden,Enchanted" }
  312. });
  313. return properties;
  314. }
  315. }
  316. \ **Note:** This method is intended for advanced purposes. For most common use cases, the scripting languages offer easier ways to handle properties. See :ref:`@GDScript.@export<class_@GDScript_annotation_@export>`, :ref:`@GDScript.@export_enum<class_@GDScript_annotation_@export_enum>`, :ref:`@GDScript.@export_group<class_@GDScript_annotation_@export_group>`, etc.
  317. \ **Note:** If the object's script is not :ref:`@GDScript.@tool<class_@GDScript_annotation_@tool>`, this method will not be called in the editor.
  318. .. rst-class:: classref-item-separator
  319. ----
  320. .. _class_Object_private_method__init:
  321. .. rst-class:: classref-method
  322. void **_init** **(** **)** |virtual|
  323. Called when the object's script is instantiated, oftentimes after the object is initialized in memory (through ``Object.new()`` in GDScript, or ``new GodotObject`` in C#). It can be also defined to take in parameters. This method is similar to a constructor in most programming languages.
  324. \ **Note:** If :ref:`_init<class_Object_private_method__init>` is defined with *required* parameters, the Object with script may only be created directly. If any other means (such as :ref:`PackedScene.instantiate<class_PackedScene_method_instantiate>` or :ref:`Node.duplicate<class_Node_method_duplicate>`) are used, the script's initialization will fail.
  325. .. rst-class:: classref-item-separator
  326. ----
  327. .. _class_Object_private_method__notification:
  328. .. rst-class:: classref-method
  329. void **_notification** **(** :ref:`int<class_int>` what **)** |virtual|
  330. Called when the object receives a notification, which can be identified in ``what`` by comparing it with a constant. See also :ref:`notification<class_Object_method_notification>`.
  331. .. tabs::
  332. .. code-tab:: gdscript
  333. func _notification(what):
  334. if what == NOTIFICATION_PREDELETE:
  335. print("Goodbye!")
  336. .. code-tab:: csharp
  337. public override void _Notification(int what)
  338. {
  339. if (what == NotificationPredelete)
  340. {
  341. GD.Print("Goodbye!");
  342. }
  343. }
  344. \ **Note:** The base **Object** defines a few notifications (:ref:`NOTIFICATION_POSTINITIALIZE<class_Object_constant_NOTIFICATION_POSTINITIALIZE>` and :ref:`NOTIFICATION_PREDELETE<class_Object_constant_NOTIFICATION_PREDELETE>`). Inheriting classes such as :ref:`Node<class_Node>` define a lot more notifications, which are also received by this method.
  345. .. rst-class:: classref-item-separator
  346. ----
  347. .. _class_Object_private_method__property_can_revert:
  348. .. rst-class:: classref-method
  349. :ref:`bool<class_bool>` **_property_can_revert** **(** :ref:`StringName<class_StringName>` property **)** |virtual|
  350. Override this method to customize the given ``property``'s revert behavior. Should return ``true`` if the ``property`` can be reverted in the Inspector dock. Use :ref:`_property_get_revert<class_Object_private_method__property_get_revert>` to specify the ``property``'s default value.
  351. \ **Note:** This method must return consistently, regardless of the current value of the ``property``.
  352. .. rst-class:: classref-item-separator
  353. ----
  354. .. _class_Object_private_method__property_get_revert:
  355. .. rst-class:: classref-method
  356. :ref:`Variant<class_Variant>` **_property_get_revert** **(** :ref:`StringName<class_StringName>` property **)** |virtual|
  357. Override this method to customize the given ``property``'s revert behavior. Should return the default value for the ``property``. If the default value differs from the ``property``'s current value, a revert icon is displayed in the Inspector dock.
  358. \ **Note:** :ref:`_property_can_revert<class_Object_private_method__property_can_revert>` must also be overridden for this method to be called.
  359. .. rst-class:: classref-item-separator
  360. ----
  361. .. _class_Object_private_method__set:
  362. .. rst-class:: classref-method
  363. :ref:`bool<class_bool>` **_set** **(** :ref:`StringName<class_StringName>` property, :ref:`Variant<class_Variant>` value **)** |virtual|
  364. Override this method to customize the behavior of :ref:`set<class_Object_method_set>`. Should set the ``property`` to ``value`` and return ``true``, or ``false`` if the ``property`` should be handled normally. The *exact* way to set the ``property`` is up to this method's implementation.
  365. Combined with :ref:`_get<class_Object_private_method__get>` and :ref:`_get_property_list<class_Object_private_method__get_property_list>`, this method allows defining custom properties, which is particularly useful for editor plugins. Note that a property *must* be present in :ref:`get_property_list<class_Object_method_get_property_list>`, otherwise this method will not be called.
  366. .. tabs::
  367. .. code-tab:: gdscript
  368. var internal_data = {}
  369. func _set(property, value):
  370. if property == "fake_property":
  371. # Storing the value in the fake property.
  372. internal_data["fake_property"] = value
  373. return true
  374. return false
  375. func _get_property_list():
  376. return [
  377. { "name": "fake_property", "type": TYPE_INT }
  378. ]
  379. .. code-tab:: csharp
  380. private Godot.Collections.Dictionary _internalData = new Godot.Collections.Dictionary();
  381. public override bool _Set(StringName property, Variant value)
  382. {
  383. if (property == "FakeProperty")
  384. {
  385. // Storing the value in the fake property.
  386. _internalData["FakeProperty"] = value;
  387. return true;
  388. }
  389. return false;
  390. }
  391. public override Godot.Collections.Array<Godot.Collections.Dictionary> _GetPropertyList()
  392. {
  393. return new Godot.Collections.Array<Godot.Collections.Dictionary>()
  394. {
  395. new Godot.Collections.Dictionary()
  396. {
  397. { "name", "FakeProperty" },
  398. { "type", (int)Variant.Type.Int }
  399. }
  400. };
  401. }
  402. .. rst-class:: classref-item-separator
  403. ----
  404. .. _class_Object_private_method__to_string:
  405. .. rst-class:: classref-method
  406. :ref:`String<class_String>` **_to_string** **(** **)** |virtual|
  407. Override this method to customize the return value of :ref:`to_string<class_Object_method_to_string>`, and therefore the object's representation as a :ref:`String<class_String>`.
  408. ::
  409. func _to_string():
  410. return "Welcome to Godot 4!"
  411. func _init():
  412. print(self) # Prints Welcome to Godot 4!"
  413. var a = str(self) # a is "Welcome to Godot 4!"
  414. .. rst-class:: classref-item-separator
  415. ----
  416. .. _class_Object_private_method__validate_property:
  417. .. rst-class:: classref-method
  418. void **_validate_property** **(** :ref:`Dictionary<class_Dictionary>` property **)** |virtual|
  419. Override this method to customize existing properties. Every property info goes through this method. The dictionary contents is the same as in :ref:`_get_property_list<class_Object_private_method__get_property_list>`.
  420. .. tabs::
  421. .. code-tab:: gdscript
  422. @tool
  423. extends Node
  424. @export var is_number_editable: bool:
  425. set(value):
  426. is_number_editable = value
  427. notify_property_list_changed()
  428. @export var number: int
  429. func _validate_property(property: Dictionary):
  430. if property.name == "number" and not is_number_editable:
  431. property.usage |= PROPERTY_USAGE_READ_ONLY
  432. .. code-tab:: csharp
  433. [Tool]
  434. public partial class MyNode : Node
  435. {
  436. private bool _isNumberEditable;
  437. [Export]
  438. public bool IsNumberEditable
  439. {
  440. get => _isNumberEditable;
  441. set
  442. {
  443. _isNumberEditable = value;
  444. NotifyPropertyListChanged();
  445. }
  446. }
  447. [Export]
  448. public int Number { get; set; }
  449. public override void _ValidateProperty(Godot.Collections.Dictionary property)
  450. {
  451. if (property["name"].AsStringName() == PropertyName.Number && IsNumberEditable)
  452. {
  453. var usage = property["usage"].As<PropertyUsageFlags>() | PropertyUsageFlags.ReadOnly;
  454. property["usage"] = (int)usage;
  455. }
  456. }
  457. }
  458. .. rst-class:: classref-item-separator
  459. ----
  460. .. _class_Object_method_add_user_signal:
  461. .. rst-class:: classref-method
  462. void **add_user_signal** **(** :ref:`String<class_String>` signal, :ref:`Array<class_Array>` arguments=[] **)**
  463. Adds a user-defined ``signal``. Optional arguments for the signal can be added as an :ref:`Array<class_Array>` of dictionaries, each defining a ``name`` :ref:`String<class_String>` and a ``type`` :ref:`int<class_int>` (see :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>`). See also :ref:`has_user_signal<class_Object_method_has_user_signal>`.
  464. .. tabs::
  465. .. code-tab:: gdscript
  466. add_user_signal("hurt", [
  467. { "name": "damage", "type": TYPE_INT },
  468. { "name": "source", "type": TYPE_OBJECT }
  469. ])
  470. .. code-tab:: csharp
  471. AddUserSignal("Hurt", new Godot.Collections.Array()
  472. {
  473. new Godot.Collections.Dictionary()
  474. {
  475. { "name", "damage" },
  476. { "type", (int)Variant.Type.Int }
  477. },
  478. new Godot.Collections.Dictionary()
  479. {
  480. { "name", "source" },
  481. { "type", (int)Variant.Type.Object }
  482. }
  483. });
  484. .. rst-class:: classref-item-separator
  485. ----
  486. .. _class_Object_method_call:
  487. .. rst-class:: classref-method
  488. :ref:`Variant<class_Variant>` **call** **(** :ref:`StringName<class_StringName>` method, ... **)** |vararg|
  489. Calls the ``method`` on the object and returns the result. This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
  490. .. tabs::
  491. .. code-tab:: gdscript
  492. var node = Node3D.new()
  493. node.call("rotate", Vector3(1.0, 0.0, 0.0), 1.571)
  494. .. code-tab:: csharp
  495. var node = new Node3D();
  496. node.Call(Node3D.MethodName.Rotate, new Vector3(1f, 0f, 0f), 1.571f);
  497. \ **Note:** In C#, ``method`` must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the ``MethodName`` class to avoid allocating a new :ref:`StringName<class_StringName>` on each call.
  498. .. rst-class:: classref-item-separator
  499. ----
  500. .. _class_Object_method_call_deferred:
  501. .. rst-class:: classref-method
  502. :ref:`Variant<class_Variant>` **call_deferred** **(** :ref:`StringName<class_StringName>` method, ... **)** |vararg|
  503. Calls the ``method`` on the object during idle time. Always returns null, **not** the method's result.
  504. Idle time happens mainly at the end of process and physics frames. In it, deferred calls will be run until there are none left, which means you can defer calls from other deferred calls and they'll still be run in the current idle time cycle. This means you should not call a method deferred from itself (or from a method called by it), as this causes infinite recursion the same way as if you had called the method directly.
  505. This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
  506. .. tabs::
  507. .. code-tab:: gdscript
  508. var node = Node3D.new()
  509. node.call_deferred("rotate", Vector3(1.0, 0.0, 0.0), 1.571)
  510. .. code-tab:: csharp
  511. var node = new Node3D();
  512. node.CallDeferred(Node3D.MethodName.Rotate, new Vector3(1f, 0f, 0f), 1.571f);
  513. See also :ref:`Callable.call_deferred<class_Callable_method_call_deferred>`.
  514. \ **Note:** In C#, ``method`` must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the ``MethodName`` class to avoid allocating a new :ref:`StringName<class_StringName>` on each call.
  515. \ **Note:** If you're looking to delay the function call by a frame, refer to the :ref:`SceneTree.process_frame<class_SceneTree_signal_process_frame>` and :ref:`SceneTree.physics_frame<class_SceneTree_signal_physics_frame>` signals.
  516. ::
  517. var node = Node3D.new()
  518. # Make a Callable and bind the arguments to the node's rotate() call.
  519. var callable = node.rotate.bind(Vector3(1.0, 0.0, 0.0), 1.571)
  520. # Connect the callable to the process_frame signal, so it gets called in the next process frame.
  521. # CONNECT_ONE_SHOT makes sure it only gets called once instead of every frame.
  522. get_tree().process_frame.connect(callable, CONNECT_ONE_SHOT)
  523. .. rst-class:: classref-item-separator
  524. ----
  525. .. _class_Object_method_callv:
  526. .. rst-class:: classref-method
  527. :ref:`Variant<class_Variant>` **callv** **(** :ref:`StringName<class_StringName>` method, :ref:`Array<class_Array>` arg_array **)**
  528. Calls the ``method`` on the object and returns the result. Unlike :ref:`call<class_Object_method_call>`, this method expects all parameters to be contained inside ``arg_array``.
  529. .. tabs::
  530. .. code-tab:: gdscript
  531. var node = Node3D.new()
  532. node.callv("rotate", [Vector3(1.0, 0.0, 0.0), 1.571])
  533. .. code-tab:: csharp
  534. var node = new Node3D();
  535. node.Callv(Node3D.MethodName.Rotate, new Godot.Collections.Array { new Vector3(1f, 0f, 0f), 1.571f });
  536. \ **Note:** In C#, ``method`` must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the ``MethodName`` class to avoid allocating a new :ref:`StringName<class_StringName>` on each call.
  537. .. rst-class:: classref-item-separator
  538. ----
  539. .. _class_Object_method_can_translate_messages:
  540. .. rst-class:: classref-method
  541. :ref:`bool<class_bool>` **can_translate_messages** **(** **)** |const|
  542. Returns ``true`` if the object is allowed to translate messages with :ref:`tr<class_Object_method_tr>` and :ref:`tr_n<class_Object_method_tr_n>`. See also :ref:`set_message_translation<class_Object_method_set_message_translation>`.
  543. .. rst-class:: classref-item-separator
  544. ----
  545. .. _class_Object_method_cancel_free:
  546. .. rst-class:: classref-method
  547. void **cancel_free** **(** **)**
  548. If this method is called during :ref:`NOTIFICATION_PREDELETE<class_Object_constant_NOTIFICATION_PREDELETE>`, this object will reject being freed and will remain allocated. This is mostly an internal function used for error handling to avoid the user from freeing objects when they are not intended to.
  549. .. rst-class:: classref-item-separator
  550. ----
  551. .. _class_Object_method_connect:
  552. .. rst-class:: classref-method
  553. :ref:`Error<enum_@GlobalScope_Error>` **connect** **(** :ref:`StringName<class_StringName>` signal, :ref:`Callable<class_Callable>` callable, :ref:`int<class_int>` flags=0 **)**
  554. Connects a ``signal`` by name to a ``callable``. Optional ``flags`` can be also added to configure the connection's behavior (see :ref:`ConnectFlags<enum_Object_ConnectFlags>` constants).
  555. A signal can only be connected once to the same :ref:`Callable<class_Callable>`. If the signal is already connected, this method returns :ref:`@GlobalScope.ERR_INVALID_PARAMETER<class_@GlobalScope_constant_ERR_INVALID_PARAMETER>` and pushes an error message, unless the signal is connected with :ref:`CONNECT_REFERENCE_COUNTED<class_Object_constant_CONNECT_REFERENCE_COUNTED>`. To prevent this, use :ref:`is_connected<class_Object_method_is_connected>` first to check for existing connections.
  556. If the ``callable``'s object is freed, the connection will be lost.
  557. \ **Examples with recommended syntax:**\
  558. 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.
  559. .. tabs::
  560. .. code-tab:: gdscript
  561. func _ready():
  562. var button = Button.new()
  563. # `button_down` here is a Signal variant type, and we thus call the Signal.connect() method, not Object.connect().
  564. # See discussion below for a more in-depth overview of the API.
  565. button.button_down.connect(_on_button_down)
  566. # This assumes that a `Player` class exists, which defines a `hit` signal.
  567. var player = Player.new()
  568. # We use Signal.connect() again, and we also use the Callable.bind() method,
  569. # which returns a new Callable with the parameter binds.
  570. player.hit.connect(_on_player_hit.bind("sword", 100))
  571. func _on_button_down():
  572. print("Button down!")
  573. func _on_player_hit(weapon_type, damage):
  574. print("Hit with weapon %s for %d damage." % [weapon_type, damage])
  575. .. code-tab:: csharp
  576. public override void _Ready()
  577. {
  578. var button = new Button();
  579. // C# supports passing signals as events, so we can use this idiomatic construct:
  580. button.ButtonDown += OnButtonDown;
  581. // This assumes that a `Player` class exists, which defines a `Hit` signal.
  582. var player = new Player();
  583. // We can use lambdas when we need to bind additional parameters.
  584. player.Hit += () => OnPlayerHit("sword", 100);
  585. }
  586. private void OnButtonDown()
  587. {
  588. GD.Print("Button down!");
  589. }
  590. private void OnPlayerHit(string weaponType, int damage)
  591. {
  592. GD.Print($"Hit with weapon {weaponType} for {damage} damage.");
  593. }
  594. \ **\ ``Object.connect()`` or ``Signal.connect()``?**\
  595. 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.
  596. .. tabs::
  597. .. code-tab:: gdscript
  598. func _ready():
  599. var button = Button.new()
  600. # Option 1: Object.connect() with an implicit Callable for the defined function.
  601. button.connect("button_down", _on_button_down)
  602. # Option 2: Object.connect() with a constructed Callable using a target object and method name.
  603. button.connect("button_down", Callable(self, "_on_button_down"))
  604. # Option 3: Signal.connect() with an implicit Callable for the defined function.
  605. button.button_down.connect(_on_button_down)
  606. # Option 4: Signal.connect() with a constructed Callable using a target object and method name.
  607. button.button_down.connect(Callable(self, "_on_button_down"))
  608. func _on_button_down():
  609. print("Button down!")
  610. .. code-tab:: csharp
  611. public override void _Ready()
  612. {
  613. var button = new Button();
  614. // Option 1: In C#, we can use signals as events and connect with this idiomatic syntax:
  615. button.ButtonDown += OnButtonDown;
  616. // Option 2: GodotObject.Connect() with a constructed Callable from a method group.
  617. button.Connect(Button.SignalName.ButtonDown, Callable.From(OnButtonDown));
  618. // Option 3: GodotObject.Connect() with a constructed Callable using a target object and method name.
  619. button.Connect(Button.SignalName.ButtonDown, new Callable(this, MethodName.OnButtonDown));
  620. }
  621. private void OnButtonDown()
  622. {
  623. GD.Print("Button down!");
  624. }
  625. 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 print a compile-time error if either the ``button_down`` :ref:`Signal<class_Signal>` or the ``_on_button_down`` :ref:`Callable<class_Callable>` are not defined. On the other hand, **option 2** only relies on string names and will only be able to validate either names at runtime: it will print 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.
  626. \ **Binding and passing parameters:**\
  627. The syntax to bind parameters is through :ref:`Callable.bind<class_Callable_method_bind>`, which returns a copy of the :ref:`Callable<class_Callable>` with its parameters bound.
  628. When calling :ref:`emit_signal<class_Object_method_emit_signal>`, the signal parameters can be also passed. The examples below show the relationship between these signal parameters and bound parameters.
  629. .. tabs::
  630. .. code-tab:: gdscript
  631. func _ready():
  632. # This assumes that a `Player` class exists, which defines a `hit` signal.
  633. var player = Player.new()
  634. # Using Callable.bind().
  635. player.hit.connect(_on_player_hit.bind("sword", 100))
  636. # Parameters added when emitting the signal are passed first.
  637. player.emit_signal("hit", "Dark lord", 5)
  638. # We pass two arguments when emitting (`hit_by`, `level`),
  639. # and bind two more arguments when connecting (`weapon_type`, `damage`).
  640. func _on_player_hit(hit_by, level, weapon_type, damage):
  641. print("Hit by %s (level %d) with weapon %s for %d damage." % [hit_by, level, weapon_type, damage])
  642. .. code-tab:: csharp
  643. public override void _Ready()
  644. {
  645. // This assumes that a `Player` class exists, which defines a `Hit` signal.
  646. var player = new Player();
  647. // Using lambda expressions that create a closure that captures the additional parameters.
  648. // The lambda only receives the parameters defined by the signal's delegate.
  649. player.Hit += (hitBy, level) => OnPlayerHit(hitBy, level, "sword", 100);
  650. // Parameters added when emitting the signal are passed first.
  651. player.EmitSignal(SignalName.Hit, "Dark lord", 5);
  652. }
  653. // We pass two arguments when emitting (`hit_by`, `level`),
  654. // and bind two more arguments when connecting (`weapon_type`, `damage`).
  655. private void OnPlayerHit(string hitBy, int level, string weaponType, int damage)
  656. {
  657. GD.Print($"Hit by {hitBy} (level {level}) with weapon {weaponType} for {damage} damage.");
  658. }
  659. .. rst-class:: classref-item-separator
  660. ----
  661. .. _class_Object_method_disconnect:
  662. .. rst-class:: classref-method
  663. void **disconnect** **(** :ref:`StringName<class_StringName>` signal, :ref:`Callable<class_Callable>` callable **)**
  664. Disconnects a ``signal`` by name from a given ``callable``. If the connection does not exist, generates an error. Use :ref:`is_connected<class_Object_method_is_connected>` to make sure that the connection exists.
  665. .. rst-class:: classref-item-separator
  666. ----
  667. .. _class_Object_method_emit_signal:
  668. .. rst-class:: classref-method
  669. :ref:`Error<enum_@GlobalScope_Error>` **emit_signal** **(** :ref:`StringName<class_StringName>` signal, ... **)** |vararg|
  670. Emits the given ``signal`` by name. The signal must exist, so it should be a built-in signal of this class or one of its inherited classes, or a user-defined signal (see :ref:`add_user_signal<class_Object_method_add_user_signal>`). This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
  671. Returns :ref:`@GlobalScope.ERR_UNAVAILABLE<class_@GlobalScope_constant_ERR_UNAVAILABLE>` if ``signal`` does not exist or the parameters are invalid.
  672. .. tabs::
  673. .. code-tab:: gdscript
  674. emit_signal("hit", "sword", 100)
  675. emit_signal("game_over")
  676. .. code-tab:: csharp
  677. EmitSignal(SignalName.Hit, "sword", 100);
  678. EmitSignal(SignalName.GameOver);
  679. \ **Note:** In C#, ``signal`` must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the ``SignalName`` class to avoid allocating a new :ref:`StringName<class_StringName>` on each call.
  680. .. rst-class:: classref-item-separator
  681. ----
  682. .. _class_Object_method_free:
  683. .. rst-class:: classref-method
  684. void **free** **(** **)**
  685. Deletes the object from memory. Pre-existing references to the object become invalid, and any attempt to access them will result in a run-time error. Checking the references with :ref:`@GlobalScope.is_instance_valid<class_@GlobalScope_method_is_instance_valid>` will return ``false``.
  686. .. rst-class:: classref-item-separator
  687. ----
  688. .. _class_Object_method_get:
  689. .. rst-class:: classref-method
  690. :ref:`Variant<class_Variant>` **get** **(** :ref:`StringName<class_StringName>` property **)** |const|
  691. Returns the :ref:`Variant<class_Variant>` value of the given ``property``. If the ``property`` does not exist, this method returns ``null``.
  692. .. tabs::
  693. .. code-tab:: gdscript
  694. var node = Node2D.new()
  695. node.rotation = 1.5
  696. var a = node.get("rotation") # a is 1.5
  697. .. code-tab:: csharp
  698. var node = new Node2D();
  699. node.Rotation = 1.5f;
  700. var a = node.Get(Node2D.PropertyName.Rotation); // a is 1.5
  701. \ **Note:** In C#, ``property`` must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the ``PropertyName`` class to avoid allocating a new :ref:`StringName<class_StringName>` on each call.
  702. .. rst-class:: classref-item-separator
  703. ----
  704. .. _class_Object_method_get_class:
  705. .. rst-class:: classref-method
  706. :ref:`String<class_String>` **get_class** **(** **)** |const|
  707. Returns the object's built-in class name, as a :ref:`String<class_String>`. See also :ref:`is_class<class_Object_method_is_class>`.
  708. \ **Note:** This method ignores ``class_name`` declarations. If this object's script has defined a ``class_name``, the base, built-in class name is returned instead.
  709. .. rst-class:: classref-item-separator
  710. ----
  711. .. _class_Object_method_get_incoming_connections:
  712. .. rst-class:: classref-method
  713. :ref:`Dictionary[]<class_Dictionary>` **get_incoming_connections** **(** **)** |const|
  714. Returns an :ref:`Array<class_Array>` of signal connections received by this object. Each connection is represented as a :ref:`Dictionary<class_Dictionary>` that contains three entries:
  715. - ``signal`` is a reference to the :ref:`Signal<class_Signal>`;
  716. - ``callable`` is a reference to the :ref:`Callable<class_Callable>`;
  717. - ``flags`` is a combination of :ref:`ConnectFlags<enum_Object_ConnectFlags>`.
  718. .. rst-class:: classref-item-separator
  719. ----
  720. .. _class_Object_method_get_indexed:
  721. .. rst-class:: classref-method
  722. :ref:`Variant<class_Variant>` **get_indexed** **(** :ref:`NodePath<class_NodePath>` property_path **)** |const|
  723. 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.
  724. \ **Examples:** ``"position:x"`` or ``"material:next_pass:blend_mode"``.
  725. .. tabs::
  726. .. code-tab:: gdscript
  727. var node = Node2D.new()
  728. node.position = Vector2(5, -10)
  729. var a = node.get_indexed("position") # a is Vector2(5, -10)
  730. var b = node.get_indexed("position:y") # b is -10
  731. .. code-tab:: csharp
  732. var node = new Node2D();
  733. node.Position = new Vector2(5, -10);
  734. var a = node.GetIndexed("position"); // a is Vector2(5, -10)
  735. var b = node.GetIndexed("position:y"); // b is -10
  736. \ **Note:** In C#, ``property_path`` must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the ``PropertyName`` class to avoid allocating a new :ref:`StringName<class_StringName>` on each call.
  737. \ **Note:** This method does not support actual paths to nodes in the :ref:`SceneTree<class_SceneTree>`, only sub-property paths. In the context of nodes, use :ref:`Node.get_node_and_resource<class_Node_method_get_node_and_resource>` instead.
  738. .. rst-class:: classref-item-separator
  739. ----
  740. .. _class_Object_method_get_instance_id:
  741. .. rst-class:: classref-method
  742. :ref:`int<class_int>` **get_instance_id** **(** **)** |const|
  743. Returns the object's unique instance ID. This ID can be saved in :ref:`EncodedObjectAsID<class_EncodedObjectAsID>`, and can be used to retrieve this object instance with :ref:`@GlobalScope.instance_from_id<class_@GlobalScope_method_instance_from_id>`.
  744. .. rst-class:: classref-item-separator
  745. ----
  746. .. _class_Object_method_get_meta:
  747. .. rst-class:: classref-method
  748. :ref:`Variant<class_Variant>` **get_meta** **(** :ref:`StringName<class_StringName>` name, :ref:`Variant<class_Variant>` default=null **)** |const|
  749. Returns the object's metadata value for the given entry ``name``. If the entry does not exist, returns ``default``. If ``default`` is ``null``, an error is also generated.
  750. \ **Note:** A metadata's name must be a valid identifier as per :ref:`StringName.is_valid_identifier<class_StringName_method_is_valid_identifier>` method.
  751. \ **Note:** Metadata that has a name starting with an underscore (``_``) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
  752. .. rst-class:: classref-item-separator
  753. ----
  754. .. _class_Object_method_get_meta_list:
  755. .. rst-class:: classref-method
  756. :ref:`StringName[]<class_StringName>` **get_meta_list** **(** **)** |const|
  757. Returns the object's metadata entry names as a :ref:`PackedStringArray<class_PackedStringArray>`.
  758. .. rst-class:: classref-item-separator
  759. ----
  760. .. _class_Object_method_get_method_list:
  761. .. rst-class:: classref-method
  762. :ref:`Dictionary[]<class_Dictionary>` **get_method_list** **(** **)** |const|
  763. Returns this object's methods and their signatures as an :ref:`Array<class_Array>` of dictionaries. Each :ref:`Dictionary<class_Dictionary>` contains the following entries:
  764. - ``name`` is the name of the method, as a :ref:`String<class_String>`;
  765. - ``args`` is an :ref:`Array<class_Array>` of dictionaries representing the arguments;
  766. - ``default_args`` is the default arguments as an :ref:`Array<class_Array>` of variants;
  767. - ``flags`` is a combination of :ref:`MethodFlags<enum_@GlobalScope_MethodFlags>`;
  768. - ``id`` is the method's internal identifier :ref:`int<class_int>`;
  769. - ``return`` is the returned value, as a :ref:`Dictionary<class_Dictionary>`;
  770. \ **Note:** The dictionaries of ``args`` and ``return`` are formatted identically to the results of :ref:`get_property_list<class_Object_method_get_property_list>`, although not all entries are used.
  771. .. rst-class:: classref-item-separator
  772. ----
  773. .. _class_Object_method_get_property_list:
  774. .. rst-class:: classref-method
  775. :ref:`Dictionary[]<class_Dictionary>` **get_property_list** **(** **)** |const|
  776. Returns the object's property list as an :ref:`Array<class_Array>` of dictionaries. Each :ref:`Dictionary<class_Dictionary>` contains the following entries:
  777. - ``name`` is the property's name, as a :ref:`String<class_String>`;
  778. - ``class_name`` is an empty :ref:`StringName<class_StringName>`, unless the property is :ref:`@GlobalScope.TYPE_OBJECT<class_@GlobalScope_constant_TYPE_OBJECT>` and it inherits from a class;
  779. - ``type`` is the property's type, as an :ref:`int<class_int>` (see :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>`);
  780. - ``hint`` is *how* the property is meant to be edited (see :ref:`PropertyHint<enum_@GlobalScope_PropertyHint>`);
  781. - ``hint_string`` depends on the hint (see :ref:`PropertyHint<enum_@GlobalScope_PropertyHint>`);
  782. - ``usage`` is a combination of :ref:`PropertyUsageFlags<enum_@GlobalScope_PropertyUsageFlags>`.
  783. \ **Note:** In GDScript, all class members are treated as properties. In C# and GDExtension, it may be necessary to explicitly mark class members as Godot properties using decorators or attributes.
  784. .. rst-class:: classref-item-separator
  785. ----
  786. .. _class_Object_method_get_script:
  787. .. rst-class:: classref-method
  788. :ref:`Variant<class_Variant>` **get_script** **(** **)** |const|
  789. Returns the object's :ref:`Script<class_Script>` instance, or ``null`` if no script is attached.
  790. .. rst-class:: classref-item-separator
  791. ----
  792. .. _class_Object_method_get_signal_connection_list:
  793. .. rst-class:: classref-method
  794. :ref:`Dictionary[]<class_Dictionary>` **get_signal_connection_list** **(** :ref:`StringName<class_StringName>` signal **)** |const|
  795. Returns an :ref:`Array<class_Array>` of connections for the given ``signal`` name. Each connection is represented as a :ref:`Dictionary<class_Dictionary>` that contains three entries:
  796. - ``signal`` is a reference to the :ref:`Signal<class_Signal>`;
  797. - ``callable`` is a reference to the connected :ref:`Callable<class_Callable>`;
  798. - ``flags`` is a combination of :ref:`ConnectFlags<enum_Object_ConnectFlags>`.
  799. .. rst-class:: classref-item-separator
  800. ----
  801. .. _class_Object_method_get_signal_list:
  802. .. rst-class:: classref-method
  803. :ref:`Dictionary[]<class_Dictionary>` **get_signal_list** **(** **)** |const|
  804. Returns the list of existing signals as an :ref:`Array<class_Array>` of dictionaries.
  805. \ **Note:** Due of the implementation, each :ref:`Dictionary<class_Dictionary>` is formatted very similarly to the returned values of :ref:`get_method_list<class_Object_method_get_method_list>`.
  806. .. rst-class:: classref-item-separator
  807. ----
  808. .. _class_Object_method_has_meta:
  809. .. rst-class:: classref-method
  810. :ref:`bool<class_bool>` **has_meta** **(** :ref:`StringName<class_StringName>` name **)** |const|
  811. Returns ``true`` if a metadata entry is found with the given ``name``. See also :ref:`get_meta<class_Object_method_get_meta>`, :ref:`set_meta<class_Object_method_set_meta>` and :ref:`remove_meta<class_Object_method_remove_meta>`.
  812. \ **Note:** A metadata's name must be a valid identifier as per :ref:`StringName.is_valid_identifier<class_StringName_method_is_valid_identifier>` method.
  813. \ **Note:** Metadata that has a name starting with an underscore (``_``) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
  814. .. rst-class:: classref-item-separator
  815. ----
  816. .. _class_Object_method_has_method:
  817. .. rst-class:: classref-method
  818. :ref:`bool<class_bool>` **has_method** **(** :ref:`StringName<class_StringName>` method **)** |const|
  819. Returns ``true`` if the given ``method`` name exists in the object.
  820. \ **Note:** In C#, ``method`` must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the ``MethodName`` class to avoid allocating a new :ref:`StringName<class_StringName>` on each call.
  821. .. rst-class:: classref-item-separator
  822. ----
  823. .. _class_Object_method_has_signal:
  824. .. rst-class:: classref-method
  825. :ref:`bool<class_bool>` **has_signal** **(** :ref:`StringName<class_StringName>` signal **)** |const|
  826. Returns ``true`` if the given ``signal`` name exists in the object.
  827. \ **Note:** In C#, ``signal`` must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the ``SignalName`` class to avoid allocating a new :ref:`StringName<class_StringName>` on each call.
  828. .. rst-class:: classref-item-separator
  829. ----
  830. .. _class_Object_method_has_user_signal:
  831. .. rst-class:: classref-method
  832. :ref:`bool<class_bool>` **has_user_signal** **(** :ref:`StringName<class_StringName>` signal **)** |const|
  833. Returns ``true`` if the given user-defined ``signal`` name exists. Only signals added with :ref:`add_user_signal<class_Object_method_add_user_signal>` are included.
  834. .. rst-class:: classref-item-separator
  835. ----
  836. .. _class_Object_method_is_blocking_signals:
  837. .. rst-class:: classref-method
  838. :ref:`bool<class_bool>` **is_blocking_signals** **(** **)** |const|
  839. Returns ``true`` if the object is blocking its signals from being emitted. See :ref:`set_block_signals<class_Object_method_set_block_signals>`.
  840. .. rst-class:: classref-item-separator
  841. ----
  842. .. _class_Object_method_is_class:
  843. .. rst-class:: classref-method
  844. :ref:`bool<class_bool>` **is_class** **(** :ref:`String<class_String>` class **)** |const|
  845. Returns ``true`` if the object inherits from the given ``class``. See also :ref:`get_class<class_Object_method_get_class>`.
  846. .. tabs::
  847. .. code-tab:: gdscript
  848. var sprite2d = Sprite2D.new()
  849. sprite2d.is_class("Sprite2D") # Returns true
  850. sprite2d.is_class("Node") # Returns true
  851. sprite2d.is_class("Node3D") # Returns false
  852. .. code-tab:: csharp
  853. var sprite2D = new Sprite2D();
  854. sprite2D.IsClass("Sprite2D"); // Returns true
  855. sprite2D.IsClass("Node"); // Returns true
  856. sprite2D.IsClass("Node3D"); // Returns false
  857. \ **Note:** This method ignores ``class_name`` declarations in the object's script.
  858. .. rst-class:: classref-item-separator
  859. ----
  860. .. _class_Object_method_is_connected:
  861. .. rst-class:: classref-method
  862. :ref:`bool<class_bool>` **is_connected** **(** :ref:`StringName<class_StringName>` signal, :ref:`Callable<class_Callable>` callable **)** |const|
  863. Returns ``true`` if a connection exists between the given ``signal`` name and ``callable``.
  864. \ **Note:** In C#, ``signal`` must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the ``SignalName`` class to avoid allocating a new :ref:`StringName<class_StringName>` on each call.
  865. .. rst-class:: classref-item-separator
  866. ----
  867. .. _class_Object_method_is_queued_for_deletion:
  868. .. rst-class:: classref-method
  869. :ref:`bool<class_bool>` **is_queued_for_deletion** **(** **)** |const|
  870. Returns ``true`` if the :ref:`Node.queue_free<class_Node_method_queue_free>` method was called for the object.
  871. .. rst-class:: classref-item-separator
  872. ----
  873. .. _class_Object_method_notification:
  874. .. rst-class:: classref-method
  875. void **notification** **(** :ref:`int<class_int>` what, :ref:`bool<class_bool>` reversed=false **)**
  876. Sends the given ``what`` notification to all classes inherited by the object, triggering calls to :ref:`_notification<class_Object_private_method__notification>`, starting from the highest ancestor (the **Object** class) and going down to the object's script.
  877. If ``reversed`` is ``true``, the call order is reversed.
  878. .. tabs::
  879. .. code-tab:: gdscript
  880. var player = Node2D.new()
  881. player.set_script(load("res://player.gd"))
  882. player.notification(NOTIFICATION_ENTER_TREE)
  883. # The call order is Object -> Node -> Node2D -> player.gd.
  884. player.notification(NOTIFICATION_ENTER_TREE, true)
  885. # The call order is player.gd -> Node2D -> Node -> Object.
  886. .. code-tab:: csharp
  887. var player = new Node2D();
  888. player.SetScript(GD.Load("res://player.gd"));
  889. player.Notification(NotificationEnterTree);
  890. // The call order is GodotObject -> Node -> Node2D -> player.gd.
  891. player.Notification(NotificationEnterTree, true);
  892. // The call order is player.gd -> Node2D -> Node -> GodotObject.
  893. .. rst-class:: classref-item-separator
  894. ----
  895. .. _class_Object_method_notify_property_list_changed:
  896. .. rst-class:: classref-method
  897. void **notify_property_list_changed** **(** **)**
  898. Emits the :ref:`property_list_changed<class_Object_signal_property_list_changed>` signal. This is mainly used to refresh the editor, so that the Inspector and editor plugins are properly updated.
  899. .. rst-class:: classref-item-separator
  900. ----
  901. .. _class_Object_method_property_can_revert:
  902. .. rst-class:: classref-method
  903. :ref:`bool<class_bool>` **property_can_revert** **(** :ref:`StringName<class_StringName>` property **)** |const|
  904. Returns ``true`` if the given ``property`` has a custom default value. Use :ref:`property_get_revert<class_Object_method_property_get_revert>` to get the ``property``'s default value.
  905. \ **Note:** This method is used by the Inspector dock to display a revert icon. The object must implement :ref:`_property_can_revert<class_Object_private_method__property_can_revert>` to customize the default value. If :ref:`_property_can_revert<class_Object_private_method__property_can_revert>` is not implemented, this method returns ``false``.
  906. .. rst-class:: classref-item-separator
  907. ----
  908. .. _class_Object_method_property_get_revert:
  909. .. rst-class:: classref-method
  910. :ref:`Variant<class_Variant>` **property_get_revert** **(** :ref:`StringName<class_StringName>` property **)** |const|
  911. Returns the custom default value of the given ``property``. Use :ref:`property_can_revert<class_Object_method_property_can_revert>` to check if the ``property`` has a custom default value.
  912. \ **Note:** This method is used by the Inspector dock to display a revert icon. The object must implement :ref:`_property_get_revert<class_Object_private_method__property_get_revert>` to customize the default value. If :ref:`_property_get_revert<class_Object_private_method__property_get_revert>` is not implemented, this method returns ``null``.
  913. .. rst-class:: classref-item-separator
  914. ----
  915. .. _class_Object_method_remove_meta:
  916. .. rst-class:: classref-method
  917. void **remove_meta** **(** :ref:`StringName<class_StringName>` name **)**
  918. Removes the given entry ``name`` from the object's metadata. See also :ref:`has_meta<class_Object_method_has_meta>`, :ref:`get_meta<class_Object_method_get_meta>` and :ref:`set_meta<class_Object_method_set_meta>`.
  919. \ **Note:** A metadata's name must be a valid identifier as per :ref:`StringName.is_valid_identifier<class_StringName_method_is_valid_identifier>` method.
  920. \ **Note:** Metadata that has a name starting with an underscore (``_``) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
  921. .. rst-class:: classref-item-separator
  922. ----
  923. .. _class_Object_method_set:
  924. .. rst-class:: classref-method
  925. void **set** **(** :ref:`StringName<class_StringName>` property, :ref:`Variant<class_Variant>` value **)**
  926. Assigns ``value`` to the given ``property``. If the property does not exist or the given ``value``'s type doesn't match, nothing happens.
  927. .. tabs::
  928. .. code-tab:: gdscript
  929. var node = Node2D.new()
  930. node.set("global_scale", Vector2(8, 2.5))
  931. print(node.global_scale) # Prints (8, 2.5)
  932. .. code-tab:: csharp
  933. var node = new Node2D();
  934. node.Set(Node2D.PropertyName.GlobalScale, new Vector2(8, 2.5));
  935. GD.Print(node.GlobalScale); // Prints Vector2(8, 2.5)
  936. \ **Note:** In C#, ``property`` must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the ``PropertyName`` class to avoid allocating a new :ref:`StringName<class_StringName>` on each call.
  937. .. rst-class:: classref-item-separator
  938. ----
  939. .. _class_Object_method_set_block_signals:
  940. .. rst-class:: classref-method
  941. void **set_block_signals** **(** :ref:`bool<class_bool>` enable **)**
  942. If set to ``true``, the object becomes unable to emit signals. As such, :ref:`emit_signal<class_Object_method_emit_signal>` and signal connections will not work, until it is set to ``false``.
  943. .. rst-class:: classref-item-separator
  944. ----
  945. .. _class_Object_method_set_deferred:
  946. .. rst-class:: classref-method
  947. void **set_deferred** **(** :ref:`StringName<class_StringName>` property, :ref:`Variant<class_Variant>` value **)**
  948. Assigns ``value`` to the given ``property``, at the end of the current frame. This is equivalent to calling :ref:`set<class_Object_method_set>` through :ref:`call_deferred<class_Object_method_call_deferred>`.
  949. .. tabs::
  950. .. code-tab:: gdscript
  951. var node = Node2D.new()
  952. add_child(node)
  953. node.rotation = 1.5
  954. node.set_deferred("rotation", 3.0)
  955. print(node.rotation) # Prints 1.5
  956. await get_tree().process_frame
  957. print(node.rotation) # Prints 3.0
  958. .. code-tab:: csharp
  959. var node = new Node2D();
  960. node.Rotation = 1.5f;
  961. node.SetDeferred(Node2D.PropertyName.Rotation, 3f);
  962. GD.Print(node.Rotation); // Prints 1.5
  963. await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
  964. GD.Print(node.Rotation); // Prints 3.0
  965. \ **Note:** In C#, ``property`` must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the ``PropertyName`` class to avoid allocating a new :ref:`StringName<class_StringName>` on each call.
  966. .. rst-class:: classref-item-separator
  967. ----
  968. .. _class_Object_method_set_indexed:
  969. .. rst-class:: classref-method
  970. void **set_indexed** **(** :ref:`NodePath<class_NodePath>` property_path, :ref:`Variant<class_Variant>` value **)**
  971. Assigns a new ``value`` to the property identified by the ``property_path``. The path should be a :ref:`NodePath<class_NodePath>` relative to this object, and can use the colon character (``:``) to access nested properties.
  972. .. tabs::
  973. .. code-tab:: gdscript
  974. var node = Node2D.new()
  975. node.set_indexed("position", Vector2(42, 0))
  976. node.set_indexed("position:y", -10)
  977. print(node.position) # Prints (42, -10)
  978. .. code-tab:: csharp
  979. var node = new Node2D();
  980. node.SetIndexed("position", new Vector2(42, 0));
  981. node.SetIndexed("position:y", -10);
  982. GD.Print(node.Position); // Prints (42, -10)
  983. \ **Note:** In C#, ``property_path`` must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the ``PropertyName`` class to avoid allocating a new :ref:`StringName<class_StringName>` on each call.
  984. .. rst-class:: classref-item-separator
  985. ----
  986. .. _class_Object_method_set_message_translation:
  987. .. rst-class:: classref-method
  988. void **set_message_translation** **(** :ref:`bool<class_bool>` enable **)**
  989. If set to ``true``, allows the object to translate messages with :ref:`tr<class_Object_method_tr>` and :ref:`tr_n<class_Object_method_tr_n>`. Enabled by default. See also :ref:`can_translate_messages<class_Object_method_can_translate_messages>`.
  990. .. rst-class:: classref-item-separator
  991. ----
  992. .. _class_Object_method_set_meta:
  993. .. rst-class:: classref-method
  994. void **set_meta** **(** :ref:`StringName<class_StringName>` name, :ref:`Variant<class_Variant>` value **)**
  995. Adds or changes the entry ``name`` inside the object's metadata. The metadata ``value`` can be any :ref:`Variant<class_Variant>`, although some types cannot be serialized correctly.
  996. If ``value`` is ``null``, the entry is removed. This is the equivalent of using :ref:`remove_meta<class_Object_method_remove_meta>`. See also :ref:`has_meta<class_Object_method_has_meta>` and :ref:`get_meta<class_Object_method_get_meta>`.
  997. \ **Note:** A metadata's name must be a valid identifier as per :ref:`StringName.is_valid_identifier<class_StringName_method_is_valid_identifier>` method.
  998. \ **Note:** Metadata that has a name starting with an underscore (``_``) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
  999. .. rst-class:: classref-item-separator
  1000. ----
  1001. .. _class_Object_method_set_script:
  1002. .. rst-class:: classref-method
  1003. void **set_script** **(** :ref:`Variant<class_Variant>` script **)**
  1004. Attaches ``script`` to the object, and instantiates it. As a result, the script's :ref:`_init<class_Object_private_method__init>` is called. A :ref:`Script<class_Script>` is used to extend the object's functionality.
  1005. If a script already exists, its instance is detached, and its property values and state are lost. Built-in property values are still kept.
  1006. .. rst-class:: classref-item-separator
  1007. ----
  1008. .. _class_Object_method_to_string:
  1009. .. rst-class:: classref-method
  1010. :ref:`String<class_String>` **to_string** **(** **)**
  1011. Returns a :ref:`String<class_String>` representing the object. Defaults to ``"<ClassName#RID>"``. Override :ref:`_to_string<class_Object_private_method__to_string>` to customize the string representation of the object.
  1012. .. rst-class:: classref-item-separator
  1013. ----
  1014. .. _class_Object_method_tr:
  1015. .. rst-class:: classref-method
  1016. :ref:`String<class_String>` **tr** **(** :ref:`StringName<class_StringName>` message, :ref:`StringName<class_StringName>` context="" **)** |const|
  1017. Translates a ``message``, using the translation catalogs configured in the Project Settings. Further ``context`` can be specified to help with the translation.
  1018. If :ref:`can_translate_messages<class_Object_method_can_translate_messages>` is ``false``, or no translation is available, this method returns the ``message`` without changes. See :ref:`set_message_translation<class_Object_method_set_message_translation>`.
  1019. For detailed examples, see :doc:`Internationalizing games <../tutorials/i18n/internationalizing_games>`.
  1020. .. rst-class:: classref-item-separator
  1021. ----
  1022. .. _class_Object_method_tr_n:
  1023. .. rst-class:: classref-method
  1024. :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|
  1025. Translates a ``message`` or ``plural_message``, using the translation catalogs configured in the Project Settings. Further ``context`` can be specified to help with the translation.
  1026. If :ref:`can_translate_messages<class_Object_method_can_translate_messages>` is ``false``, or no translation is available, this method returns ``message`` or ``plural_message``, without changes. See :ref:`set_message_translation<class_Object_method_set_message_translation>`.
  1027. The ``n`` is the number, or amount, of the message's subject. It is used by the translation system to fetch the correct plural form for the current language.
  1028. For detailed examples, see :doc:`Localization using gettext <../tutorials/i18n/localization_using_gettext>`.
  1029. \ **Note:** Negative and :ref:`float<class_float>` numbers may not properly apply to some countable subjects. It's recommended handling these cases with :ref:`tr<class_Object_method_tr>`.
  1030. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  1031. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  1032. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  1033. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  1034. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  1035. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  1036. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`