class_object.rst 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919
  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/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/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:`FramebufferCacheRD<class_FramebufferCacheRD>`, :ref:`GDExtensionManager<class_GDExtensionManager>`, :ref:`Geometry2D<class_Geometry2D>`, :ref:`Geometry3D<class_Geometry3D>`, :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:`NativeMenu<class_NativeMenu>`, :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:`RenderData<class_RenderData>`, :ref:`RenderingDevice<class_RenderingDevice>`, :ref:`RenderingServer<class_RenderingServer>`, :ref:`RenderSceneData<class_RenderSceneData>`, :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:`UniformSetCacheRD<class_UniformSetCacheRD>`, :ref:`WorkerThreadPool<class_WorkerThreadPool>`, :ref:`XRServer<class_XRServer>`, :ref:`XRVRS<class_XRVRS>`
  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>`\ (\ property\: :ref:`StringName<class_StringName>`\ ) |virtual| |
  44. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Array<class_Array>`\[: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. | :ref:`Variant<class_Variant>` | :ref:`_iter_get<class_Object_private_method__iter_get>`\ (\ iter\: :ref:`Variant<class_Variant>`\ ) |virtual| |
  50. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`bool<class_bool>` | :ref:`_iter_init<class_Object_private_method__iter_init>`\ (\ iter\: :ref:`Array<class_Array>`\ ) |virtual| |
  52. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`bool<class_bool>` | :ref:`_iter_next<class_Object_private_method__iter_next>`\ (\ iter\: :ref:`Array<class_Array>`\ ) |virtual| |
  54. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | |void| | :ref:`_notification<class_Object_private_method__notification>`\ (\ what\: :ref:`int<class_int>`\ ) |virtual| |
  56. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`bool<class_bool>` | :ref:`_property_can_revert<class_Object_private_method__property_can_revert>`\ (\ property\: :ref:`StringName<class_StringName>`\ ) |virtual| |
  58. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`Variant<class_Variant>` | :ref:`_property_get_revert<class_Object_private_method__property_get_revert>`\ (\ property\: :ref:`StringName<class_StringName>`\ ) |virtual| |
  60. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`bool<class_bool>` | :ref:`_set<class_Object_private_method__set>`\ (\ property\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) |virtual| |
  62. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`String<class_String>` | :ref:`_to_string<class_Object_private_method__to_string>`\ (\ ) |virtual| |
  64. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | |void| | :ref:`_validate_property<class_Object_private_method__validate_property>`\ (\ property\: :ref:`Dictionary<class_Dictionary>`\ ) |virtual| |
  66. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | |void| | :ref:`add_user_signal<class_Object_method_add_user_signal>`\ (\ signal\: :ref:`String<class_String>`, arguments\: :ref:`Array<class_Array>` = []\ ) |
  68. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`Variant<class_Variant>` | :ref:`call<class_Object_method_call>`\ (\ method\: :ref:`StringName<class_StringName>`, ...\ ) |vararg| |
  70. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`Variant<class_Variant>` | :ref:`call_deferred<class_Object_method_call_deferred>`\ (\ method\: :ref:`StringName<class_StringName>`, ...\ ) |vararg| |
  72. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`Variant<class_Variant>` | :ref:`callv<class_Object_method_callv>`\ (\ method\: :ref:`StringName<class_StringName>`, arg_array\: :ref:`Array<class_Array>`\ ) |
  74. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`bool<class_bool>` | :ref:`can_translate_messages<class_Object_method_can_translate_messages>`\ (\ ) |const| |
  76. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | |void| | :ref:`cancel_free<class_Object_method_cancel_free>`\ (\ ) |
  78. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`connect<class_Object_method_connect>`\ (\ signal\: :ref:`StringName<class_StringName>`, callable\: :ref:`Callable<class_Callable>`, flags\: :ref:`int<class_int>` = 0\ ) |
  80. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | |void| | :ref:`disconnect<class_Object_method_disconnect>`\ (\ signal\: :ref:`StringName<class_StringName>`, callable\: :ref:`Callable<class_Callable>`\ ) |
  82. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`emit_signal<class_Object_method_emit_signal>`\ (\ signal\: :ref:`StringName<class_StringName>`, ...\ ) |vararg| |
  84. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | |void| | :ref:`free<class_Object_method_free>`\ (\ ) |
  86. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | :ref:`Variant<class_Variant>` | :ref:`get<class_Object_method_get>`\ (\ property\: :ref:`StringName<class_StringName>`\ ) |const| |
  88. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | :ref:`String<class_String>` | :ref:`get_class<class_Object_method_get_class>`\ (\ ) |const| |
  90. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`get_incoming_connections<class_Object_method_get_incoming_connections>`\ (\ ) |const| |
  92. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`Variant<class_Variant>` | :ref:`get_indexed<class_Object_method_get_indexed>`\ (\ property_path\: :ref:`NodePath<class_NodePath>`\ ) |const| |
  94. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`int<class_int>` | :ref:`get_instance_id<class_Object_method_get_instance_id>`\ (\ ) |const| |
  96. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :ref:`Variant<class_Variant>` | :ref:`get_meta<class_Object_method_get_meta>`\ (\ name\: :ref:`StringName<class_StringName>`, default\: :ref:`Variant<class_Variant>` = null\ ) |const| |
  98. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | :ref:`Array<class_Array>`\[:ref:`StringName<class_StringName>`\] | :ref:`get_meta_list<class_Object_method_get_meta_list>`\ (\ ) |const| |
  100. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | :ref:`int<class_int>` | :ref:`get_method_argument_count<class_Object_method_get_method_argument_count>`\ (\ method\: :ref:`StringName<class_StringName>`\ ) |const| |
  102. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`get_method_list<class_Object_method_get_method_list>`\ (\ ) |const| |
  104. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`get_property_list<class_Object_method_get_property_list>`\ (\ ) |const| |
  106. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | :ref:`Variant<class_Variant>` | :ref:`get_script<class_Object_method_get_script>`\ (\ ) |const| |
  108. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. | :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`get_signal_connection_list<class_Object_method_get_signal_connection_list>`\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| |
  110. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  111. | :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`get_signal_list<class_Object_method_get_signal_list>`\ (\ ) |const| |
  112. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  113. | :ref:`StringName<class_StringName>` | :ref:`get_translation_domain<class_Object_method_get_translation_domain>`\ (\ ) |const| |
  114. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  115. | :ref:`bool<class_bool>` | :ref:`has_connections<class_Object_method_has_connections>`\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| |
  116. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  117. | :ref:`bool<class_bool>` | :ref:`has_meta<class_Object_method_has_meta>`\ (\ name\: :ref:`StringName<class_StringName>`\ ) |const| |
  118. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  119. | :ref:`bool<class_bool>` | :ref:`has_method<class_Object_method_has_method>`\ (\ method\: :ref:`StringName<class_StringName>`\ ) |const| |
  120. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  121. | :ref:`bool<class_bool>` | :ref:`has_signal<class_Object_method_has_signal>`\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| |
  122. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  123. | :ref:`bool<class_bool>` | :ref:`has_user_signal<class_Object_method_has_user_signal>`\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| |
  124. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  125. | :ref:`bool<class_bool>` | :ref:`is_blocking_signals<class_Object_method_is_blocking_signals>`\ (\ ) |const| |
  126. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  127. | :ref:`bool<class_bool>` | :ref:`is_class<class_Object_method_is_class>`\ (\ class\: :ref:`String<class_String>`\ ) |const| |
  128. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  129. | :ref:`bool<class_bool>` | :ref:`is_connected<class_Object_method_is_connected>`\ (\ signal\: :ref:`StringName<class_StringName>`, callable\: :ref:`Callable<class_Callable>`\ ) |const| |
  130. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  131. | :ref:`bool<class_bool>` | :ref:`is_queued_for_deletion<class_Object_method_is_queued_for_deletion>`\ (\ ) |const| |
  132. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  133. | |void| | :ref:`notification<class_Object_method_notification>`\ (\ what\: :ref:`int<class_int>`, reversed\: :ref:`bool<class_bool>` = false\ ) |
  134. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  135. | |void| | :ref:`notify_property_list_changed<class_Object_method_notify_property_list_changed>`\ (\ ) |
  136. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  137. | :ref:`bool<class_bool>` | :ref:`property_can_revert<class_Object_method_property_can_revert>`\ (\ property\: :ref:`StringName<class_StringName>`\ ) |const| |
  138. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  139. | :ref:`Variant<class_Variant>` | :ref:`property_get_revert<class_Object_method_property_get_revert>`\ (\ property\: :ref:`StringName<class_StringName>`\ ) |const| |
  140. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  141. | |void| | :ref:`remove_meta<class_Object_method_remove_meta>`\ (\ name\: :ref:`StringName<class_StringName>`\ ) |
  142. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  143. | |void| | :ref:`remove_user_signal<class_Object_method_remove_user_signal>`\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |
  144. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  145. | |void| | :ref:`set<class_Object_method_set>`\ (\ property\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) |
  146. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  147. | |void| | :ref:`set_block_signals<class_Object_method_set_block_signals>`\ (\ enable\: :ref:`bool<class_bool>`\ ) |
  148. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  149. | |void| | :ref:`set_deferred<class_Object_method_set_deferred>`\ (\ property\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) |
  150. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  151. | |void| | :ref:`set_indexed<class_Object_method_set_indexed>`\ (\ property_path\: :ref:`NodePath<class_NodePath>`, value\: :ref:`Variant<class_Variant>`\ ) |
  152. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  153. | |void| | :ref:`set_message_translation<class_Object_method_set_message_translation>`\ (\ enable\: :ref:`bool<class_bool>`\ ) |
  154. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  155. | |void| | :ref:`set_meta<class_Object_method_set_meta>`\ (\ name\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) |
  156. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  157. | |void| | :ref:`set_script<class_Object_method_set_script>`\ (\ script\: :ref:`Variant<class_Variant>`\ ) |
  158. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  159. | |void| | :ref:`set_translation_domain<class_Object_method_set_translation_domain>`\ (\ domain\: :ref:`StringName<class_StringName>`\ ) |
  160. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  161. | :ref:`String<class_String>` | :ref:`to_string<class_Object_method_to_string>`\ (\ ) |
  162. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  163. | :ref:`String<class_String>` | :ref:`tr<class_Object_method_tr>`\ (\ message\: :ref:`StringName<class_StringName>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |const| |
  164. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  165. | :ref:`String<class_String>` | :ref:`tr_n<class_Object_method_tr_n>`\ (\ message\: :ref:`StringName<class_StringName>`, plural_message\: :ref:`StringName<class_StringName>`, n\: :ref:`int<class_int>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |const| |
  166. +------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  167. .. rst-class:: classref-section-separator
  168. ----
  169. .. rst-class:: classref-descriptions-group
  170. Signals
  171. -------
  172. .. _class_Object_signal_property_list_changed:
  173. .. rst-class:: classref-signal
  174. **property_list_changed**\ (\ ) :ref:`๐Ÿ”—<class_Object_signal_property_list_changed>`
  175. Emitted when :ref:`notify_property_list_changed<class_Object_method_notify_property_list_changed>` is called.
  176. .. rst-class:: classref-item-separator
  177. ----
  178. .. _class_Object_signal_script_changed:
  179. .. rst-class:: classref-signal
  180. **script_changed**\ (\ ) :ref:`๐Ÿ”—<class_Object_signal_script_changed>`
  181. Emitted when the object's script is changed.
  182. \ **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>`.
  183. .. rst-class:: classref-section-separator
  184. ----
  185. .. rst-class:: classref-descriptions-group
  186. Enumerations
  187. ------------
  188. .. _enum_Object_ConnectFlags:
  189. .. rst-class:: classref-enumeration
  190. enum **ConnectFlags**: :ref:`๐Ÿ”—<enum_Object_ConnectFlags>`
  191. .. _class_Object_constant_CONNECT_DEFERRED:
  192. .. rst-class:: classref-enumeration-constant
  193. :ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_DEFERRED** = ``1``
  194. Deferred connections trigger their :ref:`Callable<class_Callable>`\ s on idle time (at the end of the frame), rather than instantly.
  195. .. _class_Object_constant_CONNECT_PERSIST:
  196. .. rst-class:: classref-enumeration-constant
  197. :ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_PERSIST** = ``2``
  198. 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.
  199. .. _class_Object_constant_CONNECT_ONE_SHOT:
  200. .. rst-class:: classref-enumeration-constant
  201. :ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_ONE_SHOT** = ``4``
  202. One-shot connections disconnect themselves after emission.
  203. .. _class_Object_constant_CONNECT_REFERENCE_COUNTED:
  204. .. rst-class:: classref-enumeration-constant
  205. :ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_REFERENCE_COUNTED** = ``8``
  206. 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.
  207. .. rst-class:: classref-section-separator
  208. ----
  209. .. rst-class:: classref-descriptions-group
  210. Constants
  211. ---------
  212. .. _class_Object_constant_NOTIFICATION_POSTINITIALIZE:
  213. .. rst-class:: classref-constant
  214. **NOTIFICATION_POSTINITIALIZE** = ``0`` :ref:`๐Ÿ”—<class_Object_constant_NOTIFICATION_POSTINITIALIZE>`
  215. Notification received when the object is initialized, before its script is attached. Used internally.
  216. .. _class_Object_constant_NOTIFICATION_PREDELETE:
  217. .. rst-class:: classref-constant
  218. **NOTIFICATION_PREDELETE** = ``1`` :ref:`๐Ÿ”—<class_Object_constant_NOTIFICATION_PREDELETE>`
  219. Notification received when the object is about to be deleted. Can be used like destructors in object-oriented programming languages.
  220. .. _class_Object_constant_NOTIFICATION_EXTENSION_RELOADED:
  221. .. rst-class:: classref-constant
  222. **NOTIFICATION_EXTENSION_RELOADED** = ``2`` :ref:`๐Ÿ”—<class_Object_constant_NOTIFICATION_EXTENSION_RELOADED>`
  223. Notification received when the object finishes hot reloading. This notification is only sent for extensions classes and derived.
  224. .. rst-class:: classref-section-separator
  225. ----
  226. .. rst-class:: classref-descriptions-group
  227. Method Descriptions
  228. -------------------
  229. .. _class_Object_private_method__get:
  230. .. rst-class:: classref-method
  231. :ref:`Variant<class_Variant>` **_get**\ (\ property\: :ref:`StringName<class_StringName>`\ ) |virtual| :ref:`๐Ÿ”—<class_Object_private_method__get>`
  232. 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.
  233. 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.
  234. .. tabs::
  235. .. code-tab:: gdscript
  236. func _get(property):
  237. if property == "fake_property":
  238. print("Getting my property!")
  239. return 4
  240. func _get_property_list():
  241. return [
  242. { "name": "fake_property", "type": TYPE_INT }
  243. ]
  244. .. code-tab:: csharp
  245. public override Variant _Get(StringName property)
  246. {
  247. if (property == "FakeProperty")
  248. {
  249. GD.Print("Getting my property!");
  250. return 4;
  251. }
  252. return default;
  253. }
  254. public override Godot.Collections.Array<Godot.Collections.Dictionary> _GetPropertyList()
  255. {
  256. return new Godot.Collections.Array<Godot.Collections.Dictionary>()
  257. {
  258. new Godot.Collections.Dictionary()
  259. {
  260. { "name", "FakeProperty" },
  261. { "type", (int)Variant.Type.Int }
  262. }
  263. };
  264. }
  265. .. rst-class:: classref-item-separator
  266. ----
  267. .. _class_Object_private_method__get_property_list:
  268. .. rst-class:: classref-method
  269. :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **_get_property_list**\ (\ ) |virtual| :ref:`๐Ÿ”—<class_Object_private_method__get_property_list>`
  270. Override this method to provide a custom list of additional properties to handle by the engine.
  271. 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.
  272. You can use :ref:`_property_can_revert<class_Object_private_method__property_can_revert>` and :ref:`_property_get_revert<class_Object_private_method__property_get_revert>` to customize the default values of the properties added by this method.
  273. The example below displays a list of numbers shown as words going from ``ZERO`` to ``FIVE``, with ``number_count`` controlling the size of the list:
  274. .. tabs::
  275. .. code-tab:: gdscript
  276. @tool
  277. extends Node
  278. @export var number_count = 3:
  279. set(nc):
  280. number_count = nc
  281. numbers.resize(number_count)
  282. notify_property_list_changed()
  283. var numbers = PackedInt32Array([0, 0, 0])
  284. func _get_property_list():
  285. var properties = []
  286. for i in range(number_count):
  287. properties.append({
  288. "name": "number_%d" % i,
  289. "type": TYPE_INT,
  290. "hint": PROPERTY_HINT_ENUM,
  291. "hint_string": "ZERO,ONE,TWO,THREE,FOUR,FIVE",
  292. })
  293. return properties
  294. func _get(property):
  295. if property.begins_with("number_"):
  296. var index = property.get_slice("_", 1).to_int()
  297. return numbers[index]
  298. func _set(property, value):
  299. if property.begins_with("number_"):
  300. var index = property.get_slice("_", 1).to_int()
  301. numbers[index] = value
  302. return true
  303. return false
  304. .. code-tab:: csharp
  305. [Tool]
  306. public partial class MyNode : Node
  307. {
  308. private int _numberCount;
  309. [Export]
  310. public int NumberCount
  311. {
  312. get => _numberCount;
  313. set
  314. {
  315. _numberCount = value;
  316. _numbers.Resize(_numberCount);
  317. NotifyPropertyListChanged();
  318. }
  319. }
  320. private Godot.Collections.Array<int> _numbers = new();
  321. public override Godot.Collections.Array<Godot.Collections.Dictionary> _GetPropertyList()
  322. {
  323. var properties = new Godot.Collections.Array<Godot.Collections.Dictionary>();
  324. for (int i = 0; i < _numberCount; i++)
  325. {
  326. properties.Add(new Godot.Collections.Dictionary()
  327. {
  328. { "name", $"number_{i}" },
  329. { "type", (int)Variant.Type.Int },
  330. { "hint", (int)PropertyHint.Enum },
  331. { "hint_string", "Zero,One,Two,Three,Four,Five" },
  332. });
  333. }
  334. return properties;
  335. }
  336. public override Variant _Get(StringName property)
  337. {
  338. string propertyName = property.ToString();
  339. if (propertyName.StartsWith("number_"))
  340. {
  341. int index = int.Parse(propertyName.Substring("number_".Length));
  342. return _numbers[index];
  343. }
  344. return default;
  345. }
  346. public override bool _Set(StringName property, Variant value)
  347. {
  348. string propertyName = property.ToString();
  349. if (propertyName.StartsWith("number_"))
  350. {
  351. int index = int.Parse(propertyName.Substring("number_".Length));
  352. _numbers[index] = value.As<int>();
  353. return true;
  354. }
  355. return false;
  356. }
  357. }
  358. \ **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. If you want to customize exported properties, use :ref:`_validate_property<class_Object_private_method__validate_property>`.
  359. \ **Note:** If the object's script is not :ref:`@GDScript.@tool<class_@GDScript_annotation_@tool>`, this method will not be called in the editor.
  360. .. rst-class:: classref-item-separator
  361. ----
  362. .. _class_Object_private_method__init:
  363. .. rst-class:: classref-method
  364. |void| **_init**\ (\ ) |virtual| :ref:`๐Ÿ”—<class_Object_private_method__init>`
  365. 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.
  366. \ **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.
  367. .. rst-class:: classref-item-separator
  368. ----
  369. .. _class_Object_private_method__iter_get:
  370. .. rst-class:: classref-method
  371. :ref:`Variant<class_Variant>` **_iter_get**\ (\ iter\: :ref:`Variant<class_Variant>`\ ) |virtual| :ref:`๐Ÿ”—<class_Object_private_method__iter_get>`
  372. Returns the current iterable value. ``iter`` stores the iteration state, but unlike :ref:`_iter_init<class_Object_private_method__iter_init>` and :ref:`_iter_next<class_Object_private_method__iter_next>` the state is supposed to be read-only, so there is no :ref:`Array<class_Array>` wrapper.
  373. .. rst-class:: classref-item-separator
  374. ----
  375. .. _class_Object_private_method__iter_init:
  376. .. rst-class:: classref-method
  377. :ref:`bool<class_bool>` **_iter_init**\ (\ iter\: :ref:`Array<class_Array>`\ ) |virtual| :ref:`๐Ÿ”—<class_Object_private_method__iter_init>`
  378. Initializes the iterator. ``iter`` stores the iteration state. Since GDScript does not support passing arguments by reference, a single-element array is used as a wrapper. Returns ``true`` so long as the iterator has not reached the end.
  379. Example:
  380. ::
  381. class MyRange:
  382. var _from
  383. var _to
  384. func _init(from, to):
  385. assert(from <= to)
  386. _from = from
  387. _to = to
  388. func _iter_init(iter):
  389. iter[0] = _from
  390. return iter[0] < _to
  391. func _iter_next(iter):
  392. iter[0] += 1
  393. return iter[0] < _to
  394. func _iter_get(iter):
  395. return iter
  396. func _ready():
  397. var my_range = MyRange.new(2, 5)
  398. for x in my_range:
  399. print(x) # Prints 2, 3, 4.
  400. \ **Note:** Alternatively, you can ignore ``iter`` and use the object's state instead, see `online docs <../tutorials/scripting/gdscript/gdscript_advanced.html#custom-iterators>`__ for an example. Note that in this case you will not be able to reuse the same iterator instance in nested loops. Also, make sure you reset the iterator state in this method if you want to reuse the same instance multiple times.
  401. .. rst-class:: classref-item-separator
  402. ----
  403. .. _class_Object_private_method__iter_next:
  404. .. rst-class:: classref-method
  405. :ref:`bool<class_bool>` **_iter_next**\ (\ iter\: :ref:`Array<class_Array>`\ ) |virtual| :ref:`๐Ÿ”—<class_Object_private_method__iter_next>`
  406. Moves the iterator to the next iteration. ``iter`` stores the iteration state. Since GDScript does not support passing arguments by reference, a single-element array is used as a wrapper. Returns ``true`` so long as the iterator has not reached the end.
  407. .. rst-class:: classref-item-separator
  408. ----
  409. .. _class_Object_private_method__notification:
  410. .. rst-class:: classref-method
  411. |void| **_notification**\ (\ what\: :ref:`int<class_int>`\ ) |virtual| :ref:`๐Ÿ”—<class_Object_private_method__notification>`
  412. 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>`.
  413. .. tabs::
  414. .. code-tab:: gdscript
  415. func _notification(what):
  416. if what == NOTIFICATION_PREDELETE:
  417. print("Goodbye!")
  418. .. code-tab:: csharp
  419. public override void _Notification(int what)
  420. {
  421. if (what == NotificationPredelete)
  422. {
  423. GD.Print("Goodbye!");
  424. }
  425. }
  426. \ **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.
  427. .. rst-class:: classref-item-separator
  428. ----
  429. .. _class_Object_private_method__property_can_revert:
  430. .. rst-class:: classref-method
  431. :ref:`bool<class_bool>` **_property_can_revert**\ (\ property\: :ref:`StringName<class_StringName>`\ ) |virtual| :ref:`๐Ÿ”—<class_Object_private_method__property_can_revert>`
  432. Override this method to customize the given ``property``'s revert behavior. Should return ``true`` if the ``property`` has a custom default value and is revertible in the Inspector dock. Use :ref:`_property_get_revert<class_Object_private_method__property_get_revert>` to specify the ``property``'s default value.
  433. \ **Note:** This method must return consistently, regardless of the current value of the ``property``.
  434. .. rst-class:: classref-item-separator
  435. ----
  436. .. _class_Object_private_method__property_get_revert:
  437. .. rst-class:: classref-method
  438. :ref:`Variant<class_Variant>` **_property_get_revert**\ (\ property\: :ref:`StringName<class_StringName>`\ ) |virtual| :ref:`๐Ÿ”—<class_Object_private_method__property_get_revert>`
  439. 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.
  440. \ **Note:** :ref:`_property_can_revert<class_Object_private_method__property_can_revert>` must also be overridden for this method to be called.
  441. .. rst-class:: classref-item-separator
  442. ----
  443. .. _class_Object_private_method__set:
  444. .. rst-class:: classref-method
  445. :ref:`bool<class_bool>` **_set**\ (\ property\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) |virtual| :ref:`๐Ÿ”—<class_Object_private_method__set>`
  446. 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.
  447. 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.
  448. .. tabs::
  449. .. code-tab:: gdscript
  450. var internal_data = {}
  451. func _set(property, value):
  452. if property == "fake_property":
  453. # Storing the value in the fake property.
  454. internal_data["fake_property"] = value
  455. return true
  456. return false
  457. func _get_property_list():
  458. return [
  459. { "name": "fake_property", "type": TYPE_INT }
  460. ]
  461. .. code-tab:: csharp
  462. private Godot.Collections.Dictionary _internalData = new Godot.Collections.Dictionary();
  463. public override bool _Set(StringName property, Variant value)
  464. {
  465. if (property == "FakeProperty")
  466. {
  467. // Storing the value in the fake property.
  468. _internalData["FakeProperty"] = value;
  469. return true;
  470. }
  471. return false;
  472. }
  473. public override Godot.Collections.Array<Godot.Collections.Dictionary> _GetPropertyList()
  474. {
  475. return new Godot.Collections.Array<Godot.Collections.Dictionary>()
  476. {
  477. new Godot.Collections.Dictionary()
  478. {
  479. { "name", "FakeProperty" },
  480. { "type", (int)Variant.Type.Int }
  481. }
  482. };
  483. }
  484. .. rst-class:: classref-item-separator
  485. ----
  486. .. _class_Object_private_method__to_string:
  487. .. rst-class:: classref-method
  488. :ref:`String<class_String>` **_to_string**\ (\ ) |virtual| :ref:`๐Ÿ”—<class_Object_private_method__to_string>`
  489. 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>`.
  490. ::
  491. func _to_string():
  492. return "Welcome to Godot 4!"
  493. func _init():
  494. print(self) # Prints "Welcome to Godot 4!"
  495. var a = str(self) # a is "Welcome to Godot 4!"
  496. .. rst-class:: classref-item-separator
  497. ----
  498. .. _class_Object_private_method__validate_property:
  499. .. rst-class:: classref-method
  500. |void| **_validate_property**\ (\ property\: :ref:`Dictionary<class_Dictionary>`\ ) |virtual| :ref:`๐Ÿ”—<class_Object_private_method__validate_property>`
  501. Override this method to customize existing properties. Every property info goes through this method, except properties added with :ref:`_get_property_list<class_Object_private_method__get_property_list>`. The dictionary contents is the same as in :ref:`_get_property_list<class_Object_private_method__get_property_list>`.
  502. .. tabs::
  503. .. code-tab:: gdscript
  504. @tool
  505. extends Node
  506. @export var is_number_editable: bool:
  507. set(value):
  508. is_number_editable = value
  509. notify_property_list_changed()
  510. @export var number: int
  511. func _validate_property(property: Dictionary):
  512. if property.name == "number" and not is_number_editable:
  513. property.usage |= PROPERTY_USAGE_READ_ONLY
  514. .. code-tab:: csharp
  515. [Tool]
  516. public partial class MyNode : Node
  517. {
  518. private bool _isNumberEditable;
  519. [Export]
  520. public bool IsNumberEditable
  521. {
  522. get => _isNumberEditable;
  523. set
  524. {
  525. _isNumberEditable = value;
  526. NotifyPropertyListChanged();
  527. }
  528. }
  529. [Export]
  530. public int Number { get; set; }
  531. public override void _ValidateProperty(Godot.Collections.Dictionary property)
  532. {
  533. if (property["name"].AsStringName() == PropertyName.Number && !IsNumberEditable)
  534. {
  535. var usage = property["usage"].As<PropertyUsageFlags>() | PropertyUsageFlags.ReadOnly;
  536. property["usage"] = (int)usage;
  537. }
  538. }
  539. }
  540. .. rst-class:: classref-item-separator
  541. ----
  542. .. _class_Object_method_add_user_signal:
  543. .. rst-class:: classref-method
  544. |void| **add_user_signal**\ (\ signal\: :ref:`String<class_String>`, arguments\: :ref:`Array<class_Array>` = []\ ) :ref:`๐Ÿ”—<class_Object_method_add_user_signal>`
  545. Adds a user-defined signal named ``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>` and :ref:`remove_user_signal<class_Object_method_remove_user_signal>`.
  546. .. tabs::
  547. .. code-tab:: gdscript
  548. add_user_signal("hurt", [
  549. { "name": "damage", "type": TYPE_INT },
  550. { "name": "source", "type": TYPE_OBJECT }
  551. ])
  552. .. code-tab:: csharp
  553. AddUserSignal("Hurt", new Godot.Collections.Array()
  554. {
  555. new Godot.Collections.Dictionary()
  556. {
  557. { "name", "damage" },
  558. { "type", (int)Variant.Type.Int }
  559. },
  560. new Godot.Collections.Dictionary()
  561. {
  562. { "name", "source" },
  563. { "type", (int)Variant.Type.Object }
  564. }
  565. });
  566. .. rst-class:: classref-item-separator
  567. ----
  568. .. _class_Object_method_call:
  569. .. rst-class:: classref-method
  570. :ref:`Variant<class_Variant>` **call**\ (\ method\: :ref:`StringName<class_StringName>`, ...\ ) |vararg| :ref:`๐Ÿ”—<class_Object_method_call>`
  571. 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.
  572. .. tabs::
  573. .. code-tab:: gdscript
  574. var node = Node3D.new()
  575. node.call("rotate", Vector3(1.0, 0.0, 0.0), 1.571)
  576. .. code-tab:: csharp
  577. var node = new Node3D();
  578. node.Call(Node3D.MethodName.Rotate, new Vector3(1f, 0f, 0f), 1.571f);
  579. \ **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.
  580. .. rst-class:: classref-item-separator
  581. ----
  582. .. _class_Object_method_call_deferred:
  583. .. rst-class:: classref-method
  584. :ref:`Variant<class_Variant>` **call_deferred**\ (\ method\: :ref:`StringName<class_StringName>`, ...\ ) |vararg| :ref:`๐Ÿ”—<class_Object_method_call_deferred>`
  585. Calls the ``method`` on the object during idle time. Always returns ``null``, **not** the method's result.
  586. 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.
  587. This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
  588. .. tabs::
  589. .. code-tab:: gdscript
  590. var node = Node3D.new()
  591. node.call_deferred("rotate", Vector3(1.0, 0.0, 0.0), 1.571)
  592. .. code-tab:: csharp
  593. var node = new Node3D();
  594. node.CallDeferred(Node3D.MethodName.Rotate, new Vector3(1f, 0f, 0f), 1.571f);
  595. See also :ref:`Callable.call_deferred<class_Callable_method_call_deferred>`.
  596. \ **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.
  597. \ **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.
  598. ::
  599. var node = Node3D.new()
  600. # Make a Callable and bind the arguments to the node's rotate() call.
  601. var callable = node.rotate.bind(Vector3(1.0, 0.0, 0.0), 1.571)
  602. # Connect the callable to the process_frame signal, so it gets called in the next process frame.
  603. # CONNECT_ONE_SHOT makes sure it only gets called once instead of every frame.
  604. get_tree().process_frame.connect(callable, CONNECT_ONE_SHOT)
  605. .. rst-class:: classref-item-separator
  606. ----
  607. .. _class_Object_method_callv:
  608. .. rst-class:: classref-method
  609. :ref:`Variant<class_Variant>` **callv**\ (\ method\: :ref:`StringName<class_StringName>`, arg_array\: :ref:`Array<class_Array>`\ ) :ref:`๐Ÿ”—<class_Object_method_callv>`
  610. 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``.
  611. .. tabs::
  612. .. code-tab:: gdscript
  613. var node = Node3D.new()
  614. node.callv("rotate", [Vector3(1.0, 0.0, 0.0), 1.571])
  615. .. code-tab:: csharp
  616. var node = new Node3D();
  617. node.Callv(Node3D.MethodName.Rotate, new Godot.Collections.Array { new Vector3(1f, 0f, 0f), 1.571f });
  618. \ **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.
  619. .. rst-class:: classref-item-separator
  620. ----
  621. .. _class_Object_method_can_translate_messages:
  622. .. rst-class:: classref-method
  623. :ref:`bool<class_bool>` **can_translate_messages**\ (\ ) |const| :ref:`๐Ÿ”—<class_Object_method_can_translate_messages>`
  624. 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>`.
  625. .. rst-class:: classref-item-separator
  626. ----
  627. .. _class_Object_method_cancel_free:
  628. .. rst-class:: classref-method
  629. |void| **cancel_free**\ (\ ) :ref:`๐Ÿ”—<class_Object_method_cancel_free>`
  630. 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.
  631. .. rst-class:: classref-item-separator
  632. ----
  633. .. _class_Object_method_connect:
  634. .. rst-class:: classref-method
  635. :ref:`Error<enum_@GlobalScope_Error>` **connect**\ (\ signal\: :ref:`StringName<class_StringName>`, callable\: :ref:`Callable<class_Callable>`, flags\: :ref:`int<class_int>` = 0\ ) :ref:`๐Ÿ”—<class_Object_method_connect>`
  636. 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).
  637. 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.
  638. If the ``callable``'s object is freed, the connection will be lost.
  639. \ **Examples with recommended syntax:**\
  640. 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.
  641. .. tabs::
  642. .. code-tab:: gdscript
  643. func _ready():
  644. var button = Button.new()
  645. # `button_down` here is a Signal variant type, and we thus call the Signal.connect() method, not Object.connect().
  646. # See discussion below for a more in-depth overview of the API.
  647. button.button_down.connect(_on_button_down)
  648. # This assumes that a `Player` class exists, which defines a `hit` signal.
  649. var player = Player.new()
  650. # We use Signal.connect() again, and we also use the Callable.bind() method,
  651. # which returns a new Callable with the parameter binds.
  652. player.hit.connect(_on_player_hit.bind("sword", 100))
  653. func _on_button_down():
  654. print("Button down!")
  655. func _on_player_hit(weapon_type, damage):
  656. print("Hit with weapon %s for %d damage." % [weapon_type, damage])
  657. .. code-tab:: csharp
  658. public override void _Ready()
  659. {
  660. var button = new Button();
  661. // C# supports passing signals as events, so we can use this idiomatic construct:
  662. button.ButtonDown += OnButtonDown;
  663. // This assumes that a `Player` class exists, which defines a `Hit` signal.
  664. var player = new Player();
  665. // We can use lambdas when we need to bind additional parameters.
  666. player.Hit += () => OnPlayerHit("sword", 100);
  667. }
  668. private void OnButtonDown()
  669. {
  670. GD.Print("Button down!");
  671. }
  672. private void OnPlayerHit(string weaponType, int damage)
  673. {
  674. GD.Print($"Hit with weapon {weaponType} for {damage} damage.");
  675. }
  676. \ **\ ``Object.connect()`` or ``Signal.connect()``?**\
  677. 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.
  678. .. tabs::
  679. .. code-tab:: gdscript
  680. func _ready():
  681. var button = Button.new()
  682. # Option 1: Object.connect() with an implicit Callable for the defined function.
  683. button.connect("button_down", _on_button_down)
  684. # Option 2: Object.connect() with a constructed Callable using a target object and method name.
  685. button.connect("button_down", Callable(self, "_on_button_down"))
  686. # Option 3: Signal.connect() with an implicit Callable for the defined function.
  687. button.button_down.connect(_on_button_down)
  688. # Option 4: Signal.connect() with a constructed Callable using a target object and method name.
  689. button.button_down.connect(Callable(self, "_on_button_down"))
  690. func _on_button_down():
  691. print("Button down!")
  692. .. code-tab:: csharp
  693. public override void _Ready()
  694. {
  695. var button = new Button();
  696. // Option 1: In C#, we can use signals as events and connect with this idiomatic syntax:
  697. button.ButtonDown += OnButtonDown;
  698. // Option 2: GodotObject.Connect() with a constructed Callable from a method group.
  699. button.Connect(Button.SignalName.ButtonDown, Callable.From(OnButtonDown));
  700. // Option 3: GodotObject.Connect() with a constructed Callable using a target object and method name.
  701. button.Connect(Button.SignalName.ButtonDown, new Callable(this, MethodName.OnButtonDown));
  702. }
  703. private void OnButtonDown()
  704. {
  705. GD.Print("Button down!");
  706. }
  707. 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.
  708. \ **Binding and passing parameters:**\
  709. 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.
  710. When calling :ref:`emit_signal<class_Object_method_emit_signal>` or :ref:`Signal.emit<class_Signal_method_emit>`, the signal parameters can be also passed. The examples below show the relationship between these signal parameters and bound parameters.
  711. .. tabs::
  712. .. code-tab:: gdscript
  713. func _ready():
  714. # This assumes that a `Player` class exists, which defines a `hit` signal.
  715. var player = Player.new()
  716. # Using Callable.bind().
  717. player.hit.connect(_on_player_hit.bind("sword", 100))
  718. # Parameters added when emitting the signal are passed first.
  719. player.hit.emit("Dark lord", 5)
  720. # We pass two arguments when emitting (`hit_by`, `level`),
  721. # and bind two more arguments when connecting (`weapon_type`, `damage`).
  722. func _on_player_hit(hit_by, level, weapon_type, damage):
  723. print("Hit by %s (level %d) with weapon %s for %d damage." % [hit_by, level, weapon_type, damage])
  724. .. code-tab:: csharp
  725. public override void _Ready()
  726. {
  727. // This assumes that a `Player` class exists, which defines a `Hit` signal.
  728. var player = new Player();
  729. // Using lambda expressions that create a closure that captures the additional parameters.
  730. // The lambda only receives the parameters defined by the signal's delegate.
  731. player.Hit += (hitBy, level) => OnPlayerHit(hitBy, level, "sword", 100);
  732. // Parameters added when emitting the signal are passed first.
  733. player.EmitSignal(SignalName.Hit, "Dark lord", 5);
  734. }
  735. // We pass two arguments when emitting (`hit_by`, `level`),
  736. // and bind two more arguments when connecting (`weapon_type`, `damage`).
  737. private void OnPlayerHit(string hitBy, int level, string weaponType, int damage)
  738. {
  739. GD.Print($"Hit by {hitBy} (level {level}) with weapon {weaponType} for {damage} damage.");
  740. }
  741. .. rst-class:: classref-item-separator
  742. ----
  743. .. _class_Object_method_disconnect:
  744. .. rst-class:: classref-method
  745. |void| **disconnect**\ (\ signal\: :ref:`StringName<class_StringName>`, callable\: :ref:`Callable<class_Callable>`\ ) :ref:`๐Ÿ”—<class_Object_method_disconnect>`
  746. 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.
  747. .. rst-class:: classref-item-separator
  748. ----
  749. .. _class_Object_method_emit_signal:
  750. .. rst-class:: classref-method
  751. :ref:`Error<enum_@GlobalScope_Error>` **emit_signal**\ (\ signal\: :ref:`StringName<class_StringName>`, ...\ ) |vararg| :ref:`๐Ÿ”—<class_Object_method_emit_signal>`
  752. 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.
  753. Returns :ref:`@GlobalScope.ERR_UNAVAILABLE<class_@GlobalScope_constant_ERR_UNAVAILABLE>` if ``signal`` does not exist or the parameters are invalid.
  754. .. tabs::
  755. .. code-tab:: gdscript
  756. emit_signal("hit", "sword", 100)
  757. emit_signal("game_over")
  758. .. code-tab:: csharp
  759. EmitSignal(SignalName.Hit, "sword", 100);
  760. EmitSignal(SignalName.GameOver);
  761. \ **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.
  762. .. rst-class:: classref-item-separator
  763. ----
  764. .. _class_Object_method_free:
  765. .. rst-class:: classref-method
  766. |void| **free**\ (\ ) :ref:`๐Ÿ”—<class_Object_method_free>`
  767. 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``.
  768. .. rst-class:: classref-item-separator
  769. ----
  770. .. _class_Object_method_get:
  771. .. rst-class:: classref-method
  772. :ref:`Variant<class_Variant>` **get**\ (\ property\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`๐Ÿ”—<class_Object_method_get>`
  773. Returns the :ref:`Variant<class_Variant>` value of the given ``property``. If the ``property`` does not exist, this method returns ``null``.
  774. .. tabs::
  775. .. code-tab:: gdscript
  776. var node = Node2D.new()
  777. node.rotation = 1.5
  778. var a = node.get("rotation") # a is 1.5
  779. .. code-tab:: csharp
  780. var node = new Node2D();
  781. node.Rotation = 1.5f;
  782. var a = node.Get(Node2D.PropertyName.Rotation); // a is 1.5
  783. \ **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.
  784. .. rst-class:: classref-item-separator
  785. ----
  786. .. _class_Object_method_get_class:
  787. .. rst-class:: classref-method
  788. :ref:`String<class_String>` **get_class**\ (\ ) |const| :ref:`๐Ÿ”—<class_Object_method_get_class>`
  789. Returns the object's built-in class name, as a :ref:`String<class_String>`. See also :ref:`is_class<class_Object_method_is_class>`.
  790. \ **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.
  791. .. rst-class:: classref-item-separator
  792. ----
  793. .. _class_Object_method_get_incoming_connections:
  794. .. rst-class:: classref-method
  795. :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **get_incoming_connections**\ (\ ) |const| :ref:`๐Ÿ”—<class_Object_method_get_incoming_connections>`
  796. 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:
  797. - ``signal`` is a reference to the :ref:`Signal<class_Signal>`;
  798. - ``callable`` is a reference to the :ref:`Callable<class_Callable>`;
  799. - ``flags`` is a combination of :ref:`ConnectFlags<enum_Object_ConnectFlags>`.
  800. .. rst-class:: classref-item-separator
  801. ----
  802. .. _class_Object_method_get_indexed:
  803. .. rst-class:: classref-method
  804. :ref:`Variant<class_Variant>` **get_indexed**\ (\ property_path\: :ref:`NodePath<class_NodePath>`\ ) |const| :ref:`๐Ÿ”—<class_Object_method_get_indexed>`
  805. 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.
  806. \ **Examples:** ``"position:x"`` or ``"material:next_pass:blend_mode"``.
  807. .. tabs::
  808. .. code-tab:: gdscript
  809. var node = Node2D.new()
  810. node.position = Vector2(5, -10)
  811. var a = node.get_indexed("position") # a is Vector2(5, -10)
  812. var b = node.get_indexed("position:y") # b is -10
  813. .. code-tab:: csharp
  814. var node = new Node2D();
  815. node.Position = new Vector2(5, -10);
  816. var a = node.GetIndexed("position"); // a is Vector2(5, -10)
  817. var b = node.GetIndexed("position:y"); // b is -10
  818. \ **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.
  819. \ **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.
  820. .. rst-class:: classref-item-separator
  821. ----
  822. .. _class_Object_method_get_instance_id:
  823. .. rst-class:: classref-method
  824. :ref:`int<class_int>` **get_instance_id**\ (\ ) |const| :ref:`๐Ÿ”—<class_Object_method_get_instance_id>`
  825. 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>`.
  826. \ **Note:** This ID is only useful during the current session. It won't correspond to a similar object if the ID is sent over a network, or loaded from a file at a later time.
  827. .. rst-class:: classref-item-separator
  828. ----
  829. .. _class_Object_method_get_meta:
  830. .. rst-class:: classref-method
  831. :ref:`Variant<class_Variant>` **get_meta**\ (\ name\: :ref:`StringName<class_StringName>`, default\: :ref:`Variant<class_Variant>` = null\ ) |const| :ref:`๐Ÿ”—<class_Object_method_get_meta>`
  832. 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.
  833. \ **Note:** A metadata's name must be a valid identifier as per :ref:`StringName.is_valid_identifier<class_StringName_method_is_valid_identifier>` method.
  834. \ **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.
  835. .. rst-class:: classref-item-separator
  836. ----
  837. .. _class_Object_method_get_meta_list:
  838. .. rst-class:: classref-method
  839. :ref:`Array<class_Array>`\[:ref:`StringName<class_StringName>`\] **get_meta_list**\ (\ ) |const| :ref:`๐Ÿ”—<class_Object_method_get_meta_list>`
  840. Returns the object's metadata entry names as a :ref:`PackedStringArray<class_PackedStringArray>`.
  841. .. rst-class:: classref-item-separator
  842. ----
  843. .. _class_Object_method_get_method_argument_count:
  844. .. rst-class:: classref-method
  845. :ref:`int<class_int>` **get_method_argument_count**\ (\ method\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`๐Ÿ”—<class_Object_method_get_method_argument_count>`
  846. Returns the number of arguments of the given ``method`` by name.
  847. \ **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.
  848. .. rst-class:: classref-item-separator
  849. ----
  850. .. _class_Object_method_get_method_list:
  851. .. rst-class:: classref-method
  852. :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **get_method_list**\ (\ ) |const| :ref:`๐Ÿ”—<class_Object_method_get_method_list>`
  853. 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:
  854. - ``name`` is the name of the method, as a :ref:`String<class_String>`;
  855. - ``args`` is an :ref:`Array<class_Array>` of dictionaries representing the arguments;
  856. - ``default_args`` is the default arguments as an :ref:`Array<class_Array>` of variants;
  857. - ``flags`` is a combination of :ref:`MethodFlags<enum_@GlobalScope_MethodFlags>`;
  858. - ``id`` is the method's internal identifier :ref:`int<class_int>`;
  859. - ``return`` is the returned value, as a :ref:`Dictionary<class_Dictionary>`;
  860. \ **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.
  861. .. rst-class:: classref-item-separator
  862. ----
  863. .. _class_Object_method_get_property_list:
  864. .. rst-class:: classref-method
  865. :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **get_property_list**\ (\ ) |const| :ref:`๐Ÿ”—<class_Object_method_get_property_list>`
  866. Returns the object's property list as an :ref:`Array<class_Array>` of dictionaries. Each :ref:`Dictionary<class_Dictionary>` contains the following entries:
  867. - ``name`` is the property's name, as a :ref:`String<class_String>`;
  868. - ``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;
  869. - ``type`` is the property's type, as an :ref:`int<class_int>` (see :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>`);
  870. - ``hint`` is *how* the property is meant to be edited (see :ref:`PropertyHint<enum_@GlobalScope_PropertyHint>`);
  871. - ``hint_string`` depends on the hint (see :ref:`PropertyHint<enum_@GlobalScope_PropertyHint>`);
  872. - ``usage`` is a combination of :ref:`PropertyUsageFlags<enum_@GlobalScope_PropertyUsageFlags>`.
  873. \ **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.
  874. .. rst-class:: classref-item-separator
  875. ----
  876. .. _class_Object_method_get_script:
  877. .. rst-class:: classref-method
  878. :ref:`Variant<class_Variant>` **get_script**\ (\ ) |const| :ref:`๐Ÿ”—<class_Object_method_get_script>`
  879. Returns the object's :ref:`Script<class_Script>` instance, or ``null`` if no script is attached.
  880. .. rst-class:: classref-item-separator
  881. ----
  882. .. _class_Object_method_get_signal_connection_list:
  883. .. rst-class:: classref-method
  884. :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **get_signal_connection_list**\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`๐Ÿ”—<class_Object_method_get_signal_connection_list>`
  885. 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:
  886. - ``signal`` is a reference to the :ref:`Signal<class_Signal>`;
  887. - ``callable`` is a reference to the connected :ref:`Callable<class_Callable>`;
  888. - ``flags`` is a combination of :ref:`ConnectFlags<enum_Object_ConnectFlags>`.
  889. .. rst-class:: classref-item-separator
  890. ----
  891. .. _class_Object_method_get_signal_list:
  892. .. rst-class:: classref-method
  893. :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **get_signal_list**\ (\ ) |const| :ref:`๐Ÿ”—<class_Object_method_get_signal_list>`
  894. Returns the list of existing signals as an :ref:`Array<class_Array>` of dictionaries.
  895. \ **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>`.
  896. .. rst-class:: classref-item-separator
  897. ----
  898. .. _class_Object_method_get_translation_domain:
  899. .. rst-class:: classref-method
  900. :ref:`StringName<class_StringName>` **get_translation_domain**\ (\ ) |const| :ref:`๐Ÿ”—<class_Object_method_get_translation_domain>`
  901. Returns the name of the translation domain used by :ref:`tr<class_Object_method_tr>` and :ref:`tr_n<class_Object_method_tr_n>`. See also :ref:`TranslationServer<class_TranslationServer>`.
  902. .. rst-class:: classref-item-separator
  903. ----
  904. .. _class_Object_method_has_connections:
  905. .. rst-class:: classref-method
  906. :ref:`bool<class_bool>` **has_connections**\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`๐Ÿ”—<class_Object_method_has_connections>`
  907. Returns ``true`` if any connection exists on the given ``signal`` name.
  908. \ **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.
  909. .. rst-class:: classref-item-separator
  910. ----
  911. .. _class_Object_method_has_meta:
  912. .. rst-class:: classref-method
  913. :ref:`bool<class_bool>` **has_meta**\ (\ name\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`๐Ÿ”—<class_Object_method_has_meta>`
  914. 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>`.
  915. \ **Note:** A metadata's name must be a valid identifier as per :ref:`StringName.is_valid_identifier<class_StringName_method_is_valid_identifier>` method.
  916. \ **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.
  917. .. rst-class:: classref-item-separator
  918. ----
  919. .. _class_Object_method_has_method:
  920. .. rst-class:: classref-method
  921. :ref:`bool<class_bool>` **has_method**\ (\ method\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`๐Ÿ”—<class_Object_method_has_method>`
  922. Returns ``true`` if the given ``method`` name exists in the object.
  923. \ **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.
  924. .. rst-class:: classref-item-separator
  925. ----
  926. .. _class_Object_method_has_signal:
  927. .. rst-class:: classref-method
  928. :ref:`bool<class_bool>` **has_signal**\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`๐Ÿ”—<class_Object_method_has_signal>`
  929. Returns ``true`` if the given ``signal`` name exists in the object.
  930. \ **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.
  931. .. rst-class:: classref-item-separator
  932. ----
  933. .. _class_Object_method_has_user_signal:
  934. .. rst-class:: classref-method
  935. :ref:`bool<class_bool>` **has_user_signal**\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`๐Ÿ”—<class_Object_method_has_user_signal>`
  936. 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. See also :ref:`remove_user_signal<class_Object_method_remove_user_signal>`.
  937. .. rst-class:: classref-item-separator
  938. ----
  939. .. _class_Object_method_is_blocking_signals:
  940. .. rst-class:: classref-method
  941. :ref:`bool<class_bool>` **is_blocking_signals**\ (\ ) |const| :ref:`๐Ÿ”—<class_Object_method_is_blocking_signals>`
  942. Returns ``true`` if the object is blocking its signals from being emitted. See :ref:`set_block_signals<class_Object_method_set_block_signals>`.
  943. .. rst-class:: classref-item-separator
  944. ----
  945. .. _class_Object_method_is_class:
  946. .. rst-class:: classref-method
  947. :ref:`bool<class_bool>` **is_class**\ (\ class\: :ref:`String<class_String>`\ ) |const| :ref:`๐Ÿ”—<class_Object_method_is_class>`
  948. Returns ``true`` if the object inherits from the given ``class``. See also :ref:`get_class<class_Object_method_get_class>`.
  949. .. tabs::
  950. .. code-tab:: gdscript
  951. var sprite2d = Sprite2D.new()
  952. sprite2d.is_class("Sprite2D") # Returns true
  953. sprite2d.is_class("Node") # Returns true
  954. sprite2d.is_class("Node3D") # Returns false
  955. .. code-tab:: csharp
  956. var sprite2D = new Sprite2D();
  957. sprite2D.IsClass("Sprite2D"); // Returns true
  958. sprite2D.IsClass("Node"); // Returns true
  959. sprite2D.IsClass("Node3D"); // Returns false
  960. \ **Note:** This method ignores ``class_name`` declarations in the object's script.
  961. .. rst-class:: classref-item-separator
  962. ----
  963. .. _class_Object_method_is_connected:
  964. .. rst-class:: classref-method
  965. :ref:`bool<class_bool>` **is_connected**\ (\ signal\: :ref:`StringName<class_StringName>`, callable\: :ref:`Callable<class_Callable>`\ ) |const| :ref:`๐Ÿ”—<class_Object_method_is_connected>`
  966. Returns ``true`` if a connection exists between the given ``signal`` name and ``callable``.
  967. \ **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.
  968. .. rst-class:: classref-item-separator
  969. ----
  970. .. _class_Object_method_is_queued_for_deletion:
  971. .. rst-class:: classref-method
  972. :ref:`bool<class_bool>` **is_queued_for_deletion**\ (\ ) |const| :ref:`๐Ÿ”—<class_Object_method_is_queued_for_deletion>`
  973. Returns ``true`` if the :ref:`Node.queue_free<class_Node_method_queue_free>` method was called for the object.
  974. .. rst-class:: classref-item-separator
  975. ----
  976. .. _class_Object_method_notification:
  977. .. rst-class:: classref-method
  978. |void| **notification**\ (\ what\: :ref:`int<class_int>`, reversed\: :ref:`bool<class_bool>` = false\ ) :ref:`๐Ÿ”—<class_Object_method_notification>`
  979. 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.
  980. If ``reversed`` is ``true``, the call order is reversed.
  981. .. tabs::
  982. .. code-tab:: gdscript
  983. var player = Node2D.new()
  984. player.set_script(load("res://player.gd"))
  985. player.notification(NOTIFICATION_ENTER_TREE)
  986. # The call order is Object -> Node -> Node2D -> player.gd.
  987. player.notification(NOTIFICATION_ENTER_TREE, true)
  988. # The call order is player.gd -> Node2D -> Node -> Object.
  989. .. code-tab:: csharp
  990. var player = new Node2D();
  991. player.SetScript(GD.Load("res://player.gd"));
  992. player.Notification(NotificationEnterTree);
  993. // The call order is GodotObject -> Node -> Node2D -> player.gd.
  994. player.Notification(NotificationEnterTree, true);
  995. // The call order is player.gd -> Node2D -> Node -> GodotObject.
  996. .. rst-class:: classref-item-separator
  997. ----
  998. .. _class_Object_method_notify_property_list_changed:
  999. .. rst-class:: classref-method
  1000. |void| **notify_property_list_changed**\ (\ ) :ref:`๐Ÿ”—<class_Object_method_notify_property_list_changed>`
  1001. 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.
  1002. .. rst-class:: classref-item-separator
  1003. ----
  1004. .. _class_Object_method_property_can_revert:
  1005. .. rst-class:: classref-method
  1006. :ref:`bool<class_bool>` **property_can_revert**\ (\ property\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`๐Ÿ”—<class_Object_method_property_can_revert>`
  1007. 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.
  1008. \ **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``.
  1009. .. rst-class:: classref-item-separator
  1010. ----
  1011. .. _class_Object_method_property_get_revert:
  1012. .. rst-class:: classref-method
  1013. :ref:`Variant<class_Variant>` **property_get_revert**\ (\ property\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`๐Ÿ”—<class_Object_method_property_get_revert>`
  1014. 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.
  1015. \ **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``.
  1016. .. rst-class:: classref-item-separator
  1017. ----
  1018. .. _class_Object_method_remove_meta:
  1019. .. rst-class:: classref-method
  1020. |void| **remove_meta**\ (\ name\: :ref:`StringName<class_StringName>`\ ) :ref:`๐Ÿ”—<class_Object_method_remove_meta>`
  1021. 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>`.
  1022. \ **Note:** A metadata's name must be a valid identifier as per :ref:`StringName.is_valid_identifier<class_StringName_method_is_valid_identifier>` method.
  1023. \ **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.
  1024. .. rst-class:: classref-item-separator
  1025. ----
  1026. .. _class_Object_method_remove_user_signal:
  1027. .. rst-class:: classref-method
  1028. |void| **remove_user_signal**\ (\ signal\: :ref:`StringName<class_StringName>`\ ) :ref:`๐Ÿ”—<class_Object_method_remove_user_signal>`
  1029. Removes the given user signal ``signal`` from the object. See also :ref:`add_user_signal<class_Object_method_add_user_signal>` and :ref:`has_user_signal<class_Object_method_has_user_signal>`.
  1030. .. rst-class:: classref-item-separator
  1031. ----
  1032. .. _class_Object_method_set:
  1033. .. rst-class:: classref-method
  1034. |void| **set**\ (\ property\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) :ref:`๐Ÿ”—<class_Object_method_set>`
  1035. Assigns ``value`` to the given ``property``. If the property does not exist or the given ``value``'s type doesn't match, nothing happens.
  1036. .. tabs::
  1037. .. code-tab:: gdscript
  1038. var node = Node2D.new()
  1039. node.set("global_scale", Vector2(8, 2.5))
  1040. print(node.global_scale) # Prints (8, 2.5)
  1041. .. code-tab:: csharp
  1042. var node = new Node2D();
  1043. node.Set(Node2D.PropertyName.GlobalScale, new Vector2(8, 2.5));
  1044. GD.Print(node.GlobalScale); // Prints Vector2(8, 2.5)
  1045. \ **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.
  1046. .. rst-class:: classref-item-separator
  1047. ----
  1048. .. _class_Object_method_set_block_signals:
  1049. .. rst-class:: classref-method
  1050. |void| **set_block_signals**\ (\ enable\: :ref:`bool<class_bool>`\ ) :ref:`๐Ÿ”—<class_Object_method_set_block_signals>`
  1051. 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``.
  1052. .. rst-class:: classref-item-separator
  1053. ----
  1054. .. _class_Object_method_set_deferred:
  1055. .. rst-class:: classref-method
  1056. |void| **set_deferred**\ (\ property\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) :ref:`๐Ÿ”—<class_Object_method_set_deferred>`
  1057. 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>`.
  1058. .. tabs::
  1059. .. code-tab:: gdscript
  1060. var node = Node2D.new()
  1061. add_child(node)
  1062. node.rotation = 1.5
  1063. node.set_deferred("rotation", 3.0)
  1064. print(node.rotation) # Prints 1.5
  1065. await get_tree().process_frame
  1066. print(node.rotation) # Prints 3.0
  1067. .. code-tab:: csharp
  1068. var node = new Node2D();
  1069. node.Rotation = 1.5f;
  1070. node.SetDeferred(Node2D.PropertyName.Rotation, 3f);
  1071. GD.Print(node.Rotation); // Prints 1.5
  1072. await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
  1073. GD.Print(node.Rotation); // Prints 3.0
  1074. \ **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.
  1075. .. rst-class:: classref-item-separator
  1076. ----
  1077. .. _class_Object_method_set_indexed:
  1078. .. rst-class:: classref-method
  1079. |void| **set_indexed**\ (\ property_path\: :ref:`NodePath<class_NodePath>`, value\: :ref:`Variant<class_Variant>`\ ) :ref:`๐Ÿ”—<class_Object_method_set_indexed>`
  1080. 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.
  1081. .. tabs::
  1082. .. code-tab:: gdscript
  1083. var node = Node2D.new()
  1084. node.set_indexed("position", Vector2(42, 0))
  1085. node.set_indexed("position:y", -10)
  1086. print(node.position) # Prints (42, -10)
  1087. .. code-tab:: csharp
  1088. var node = new Node2D();
  1089. node.SetIndexed("position", new Vector2(42, 0));
  1090. node.SetIndexed("position:y", -10);
  1091. GD.Print(node.Position); // Prints (42, -10)
  1092. \ **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.
  1093. .. rst-class:: classref-item-separator
  1094. ----
  1095. .. _class_Object_method_set_message_translation:
  1096. .. rst-class:: classref-method
  1097. |void| **set_message_translation**\ (\ enable\: :ref:`bool<class_bool>`\ ) :ref:`๐Ÿ”—<class_Object_method_set_message_translation>`
  1098. 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>`.
  1099. .. rst-class:: classref-item-separator
  1100. ----
  1101. .. _class_Object_method_set_meta:
  1102. .. rst-class:: classref-method
  1103. |void| **set_meta**\ (\ name\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) :ref:`๐Ÿ”—<class_Object_method_set_meta>`
  1104. 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.
  1105. 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>`.
  1106. \ **Note:** A metadata's name must be a valid identifier as per :ref:`StringName.is_valid_identifier<class_StringName_method_is_valid_identifier>` method.
  1107. \ **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.
  1108. .. rst-class:: classref-item-separator
  1109. ----
  1110. .. _class_Object_method_set_script:
  1111. .. rst-class:: classref-method
  1112. |void| **set_script**\ (\ script\: :ref:`Variant<class_Variant>`\ ) :ref:`๐Ÿ”—<class_Object_method_set_script>`
  1113. 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.
  1114. If a script already exists, its instance is detached, and its property values and state are lost. Built-in property values are still kept.
  1115. .. rst-class:: classref-item-separator
  1116. ----
  1117. .. _class_Object_method_set_translation_domain:
  1118. .. rst-class:: classref-method
  1119. |void| **set_translation_domain**\ (\ domain\: :ref:`StringName<class_StringName>`\ ) :ref:`๐Ÿ”—<class_Object_method_set_translation_domain>`
  1120. Sets the name of the translation domain used by :ref:`tr<class_Object_method_tr>` and :ref:`tr_n<class_Object_method_tr_n>`. See also :ref:`TranslationServer<class_TranslationServer>`.
  1121. .. rst-class:: classref-item-separator
  1122. ----
  1123. .. _class_Object_method_to_string:
  1124. .. rst-class:: classref-method
  1125. :ref:`String<class_String>` **to_string**\ (\ ) :ref:`๐Ÿ”—<class_Object_method_to_string>`
  1126. 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.
  1127. .. rst-class:: classref-item-separator
  1128. ----
  1129. .. _class_Object_method_tr:
  1130. .. rst-class:: classref-method
  1131. :ref:`String<class_String>` **tr**\ (\ message\: :ref:`StringName<class_StringName>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |const| :ref:`๐Ÿ”—<class_Object_method_tr>`
  1132. Translates a ``message``, using the translation catalogs configured in the Project Settings. Further ``context`` can be specified to help with the translation. Note that most :ref:`Control<class_Control>` nodes automatically translate their strings, so this method is mostly useful for formatted strings or custom drawn text.
  1133. 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>`.
  1134. For detailed examples, see :doc:`Internationalizing games <../tutorials/i18n/internationalizing_games>`.
  1135. \ **Note:** This method can't be used without an **Object** instance, as it requires the :ref:`can_translate_messages<class_Object_method_can_translate_messages>` method. To translate strings in a static context, use :ref:`TranslationServer.translate<class_TranslationServer_method_translate>`.
  1136. .. rst-class:: classref-item-separator
  1137. ----
  1138. .. _class_Object_method_tr_n:
  1139. .. rst-class:: classref-method
  1140. :ref:`String<class_String>` **tr_n**\ (\ message\: :ref:`StringName<class_StringName>`, plural_message\: :ref:`StringName<class_StringName>`, n\: :ref:`int<class_int>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |const| :ref:`๐Ÿ”—<class_Object_method_tr_n>`
  1141. 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.
  1142. 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>`.
  1143. 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.
  1144. For detailed examples, see :doc:`Localization using gettext <../tutorials/i18n/localization_using_gettext>`.
  1145. \ **Note:** Negative and :ref:`float<class_float>` numbers may not properly apply to some countable subjects. It's recommended to handle these cases with :ref:`tr<class_Object_method_tr>`.
  1146. \ **Note:** This method can't be used without an **Object** instance, as it requires the :ref:`can_translate_messages<class_Object_method_can_translate_messages>` method. To translate strings in a static context, use :ref:`TranslationServer.translate_plural<class_TranslationServer_method_translate_plural>`.
  1147. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  1148. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  1149. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  1150. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  1151. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  1152. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  1153. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  1154. .. |void| replace:: :abbr:`void (No return value.)`