class_scenetree.rst 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  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/SceneTree.xml.
  6. .. _class_SceneTree:
  7. SceneTree
  8. =========
  9. **Inherits:** :ref:`MainLoop<class_MainLoop>` **<** :ref:`Object<class_Object>`
  10. Manages the game loop via a hierarchy of nodes.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. As one of the most important classes, the **SceneTree** manages the hierarchy of nodes in a scene as well as scenes themselves. Nodes can be added, retrieved and removed. The whole scene tree (and thus the current scene) can be paused. Scenes can be loaded, switched and reloaded.
  15. You can also use the **SceneTree** to organize your nodes into groups: every node can be assigned as many groups as you want to create, e.g. an "enemy" group. You can then iterate these groups or even call methods and set properties on all the group's members at once.
  16. \ **SceneTree** is the default :ref:`MainLoop<class_MainLoop>` implementation used by scenes, and is thus in charge of the game loop.
  17. .. rst-class:: classref-introduction-group
  18. Tutorials
  19. ---------
  20. - :doc:`SceneTree <../tutorials/scripting/scene_tree>`
  21. - :doc:`Multiple resolutions <../tutorials/rendering/multiple_resolutions>`
  22. .. rst-class:: classref-reftable-group
  23. Properties
  24. ----------
  25. .. table::
  26. :widths: auto
  27. +-----------------------------+------------------------------------------------------------------------------+-----------+
  28. | :ref:`bool<class_bool>` | :ref:`auto_accept_quit<class_SceneTree_property_auto_accept_quit>` | ``true`` |
  29. +-----------------------------+------------------------------------------------------------------------------+-----------+
  30. | :ref:`Node<class_Node>` | :ref:`current_scene<class_SceneTree_property_current_scene>` | |
  31. +-----------------------------+------------------------------------------------------------------------------+-----------+
  32. | :ref:`bool<class_bool>` | :ref:`debug_collisions_hint<class_SceneTree_property_debug_collisions_hint>` | ``false`` |
  33. +-----------------------------+------------------------------------------------------------------------------+-----------+
  34. | :ref:`bool<class_bool>` | :ref:`debug_navigation_hint<class_SceneTree_property_debug_navigation_hint>` | ``false`` |
  35. +-----------------------------+------------------------------------------------------------------------------+-----------+
  36. | :ref:`bool<class_bool>` | :ref:`debug_paths_hint<class_SceneTree_property_debug_paths_hint>` | ``false`` |
  37. +-----------------------------+------------------------------------------------------------------------------+-----------+
  38. | :ref:`Node<class_Node>` | :ref:`edited_scene_root<class_SceneTree_property_edited_scene_root>` | |
  39. +-----------------------------+------------------------------------------------------------------------------+-----------+
  40. | :ref:`bool<class_bool>` | :ref:`multiplayer_poll<class_SceneTree_property_multiplayer_poll>` | ``true`` |
  41. +-----------------------------+------------------------------------------------------------------------------+-----------+
  42. | :ref:`bool<class_bool>` | :ref:`paused<class_SceneTree_property_paused>` | ``false`` |
  43. +-----------------------------+------------------------------------------------------------------------------+-----------+
  44. | :ref:`bool<class_bool>` | :ref:`quit_on_go_back<class_SceneTree_property_quit_on_go_back>` | ``true`` |
  45. +-----------------------------+------------------------------------------------------------------------------+-----------+
  46. | :ref:`Window<class_Window>` | :ref:`root<class_SceneTree_property_root>` | |
  47. +-----------------------------+------------------------------------------------------------------------------+-----------+
  48. .. rst-class:: classref-reftable-group
  49. Methods
  50. -------
  51. .. table::
  52. :widths: auto
  53. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | void | :ref:`call_group<class_SceneTree_method_call_group>` **(** :ref:`StringName<class_StringName>` group, :ref:`StringName<class_StringName>` method, ... **)** |vararg| |
  55. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | void | :ref:`call_group_flags<class_SceneTree_method_call_group_flags>` **(** :ref:`int<class_int>` flags, :ref:`StringName<class_StringName>` group, :ref:`StringName<class_StringName>` method, ... **)** |vararg| |
  57. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`change_scene_to_file<class_SceneTree_method_change_scene_to_file>` **(** :ref:`String<class_String>` path **)** |
  59. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`change_scene_to_packed<class_SceneTree_method_change_scene_to_packed>` **(** :ref:`PackedScene<class_PackedScene>` packed_scene **)** |
  61. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`SceneTreeTimer<class_SceneTreeTimer>` | :ref:`create_timer<class_SceneTree_method_create_timer>` **(** :ref:`float<class_float>` time_sec, :ref:`bool<class_bool>` process_always=true, :ref:`bool<class_bool>` process_in_physics=false, :ref:`bool<class_bool>` ignore_time_scale=false **)** |
  63. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`Tween<class_Tween>` | :ref:`create_tween<class_SceneTree_method_create_tween>` **(** **)** |
  65. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`Node<class_Node>` | :ref:`get_first_node_in_group<class_SceneTree_method_get_first_node_in_group>` **(** :ref:`StringName<class_StringName>` group **)** |
  67. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`int<class_int>` | :ref:`get_frame<class_SceneTree_method_get_frame>` **(** **)** |const| |
  69. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`MultiplayerAPI<class_MultiplayerAPI>` | :ref:`get_multiplayer<class_SceneTree_method_get_multiplayer>` **(** :ref:`NodePath<class_NodePath>` for_path=NodePath("") **)** |const| |
  71. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`int<class_int>` | :ref:`get_node_count<class_SceneTree_method_get_node_count>` **(** **)** |const| |
  73. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`Node[]<class_Node>` | :ref:`get_nodes_in_group<class_SceneTree_method_get_nodes_in_group>` **(** :ref:`StringName<class_StringName>` group **)** |
  75. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`Tween[]<class_Tween>` | :ref:`get_processed_tweens<class_SceneTree_method_get_processed_tweens>` **(** **)** |
  77. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`bool<class_bool>` | :ref:`has_group<class_SceneTree_method_has_group>` **(** :ref:`StringName<class_StringName>` name **)** |const| |
  79. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`notify_group<class_SceneTree_method_notify_group>` **(** :ref:`StringName<class_StringName>` group, :ref:`int<class_int>` notification **)** |
  81. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | void | :ref:`notify_group_flags<class_SceneTree_method_notify_group_flags>` **(** :ref:`int<class_int>` call_flags, :ref:`StringName<class_StringName>` group, :ref:`int<class_int>` notification **)** |
  83. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | void | :ref:`queue_delete<class_SceneTree_method_queue_delete>` **(** :ref:`Object<class_Object>` obj **)** |
  85. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | void | :ref:`quit<class_SceneTree_method_quit>` **(** :ref:`int<class_int>` exit_code=0 **)** |
  87. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`reload_current_scene<class_SceneTree_method_reload_current_scene>` **(** **)** |
  89. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | void | :ref:`set_group<class_SceneTree_method_set_group>` **(** :ref:`StringName<class_StringName>` group, :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** |
  91. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | void | :ref:`set_group_flags<class_SceneTree_method_set_group_flags>` **(** :ref:`int<class_int>` call_flags, :ref:`StringName<class_StringName>` group, :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)** |
  93. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | void | :ref:`set_multiplayer<class_SceneTree_method_set_multiplayer>` **(** :ref:`MultiplayerAPI<class_MultiplayerAPI>` multiplayer, :ref:`NodePath<class_NodePath>` root_path=NodePath("") **)** |
  95. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | void | :ref:`unload_current_scene<class_SceneTree_method_unload_current_scene>` **(** **)** |
  97. +---------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. .. rst-class:: classref-section-separator
  99. ----
  100. .. rst-class:: classref-descriptions-group
  101. Signals
  102. -------
  103. .. _class_SceneTree_signal_node_added:
  104. .. rst-class:: classref-signal
  105. **node_added** **(** :ref:`Node<class_Node>` node **)**
  106. Emitted whenever a node is added to the **SceneTree**.
  107. .. rst-class:: classref-item-separator
  108. ----
  109. .. _class_SceneTree_signal_node_configuration_warning_changed:
  110. .. rst-class:: classref-signal
  111. **node_configuration_warning_changed** **(** :ref:`Node<class_Node>` node **)**
  112. Emitted when a node's configuration changed. Only emitted in ``tool`` mode.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. _class_SceneTree_signal_node_removed:
  116. .. rst-class:: classref-signal
  117. **node_removed** **(** :ref:`Node<class_Node>` node **)**
  118. Emitted whenever a node is removed from the **SceneTree**.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_SceneTree_signal_node_renamed:
  122. .. rst-class:: classref-signal
  123. **node_renamed** **(** :ref:`Node<class_Node>` node **)**
  124. Emitted whenever a node is renamed.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_SceneTree_signal_physics_frame:
  128. .. rst-class:: classref-signal
  129. **physics_frame** **(** **)**
  130. Emitted immediately before :ref:`Node._physics_process<class_Node_private_method__physics_process>` is called on every node in the **SceneTree**.
  131. .. rst-class:: classref-item-separator
  132. ----
  133. .. _class_SceneTree_signal_process_frame:
  134. .. rst-class:: classref-signal
  135. **process_frame** **(** **)**
  136. Emitted immediately before :ref:`Node._process<class_Node_private_method__process>` is called on every node in the **SceneTree**.
  137. .. rst-class:: classref-item-separator
  138. ----
  139. .. _class_SceneTree_signal_tree_changed:
  140. .. rst-class:: classref-signal
  141. **tree_changed** **(** **)**
  142. Emitted whenever the **SceneTree** hierarchy changed (children being moved or renamed, etc.).
  143. .. rst-class:: classref-item-separator
  144. ----
  145. .. _class_SceneTree_signal_tree_process_mode_changed:
  146. .. rst-class:: classref-signal
  147. **tree_process_mode_changed** **(** **)**
  148. This signal is only emitted in the editor, it allows the editor to update the visibility of disabled nodes. Emitted whenever any node's :ref:`Node.process_mode<class_Node_property_process_mode>` is changed.
  149. .. rst-class:: classref-section-separator
  150. ----
  151. .. rst-class:: classref-descriptions-group
  152. Enumerations
  153. ------------
  154. .. _enum_SceneTree_GroupCallFlags:
  155. .. rst-class:: classref-enumeration
  156. enum **GroupCallFlags**:
  157. .. _class_SceneTree_constant_GROUP_CALL_DEFAULT:
  158. .. rst-class:: classref-enumeration-constant
  159. :ref:`GroupCallFlags<enum_SceneTree_GroupCallFlags>` **GROUP_CALL_DEFAULT** = ``0``
  160. Call a group with no flags (default).
  161. .. _class_SceneTree_constant_GROUP_CALL_REVERSE:
  162. .. rst-class:: classref-enumeration-constant
  163. :ref:`GroupCallFlags<enum_SceneTree_GroupCallFlags>` **GROUP_CALL_REVERSE** = ``1``
  164. Call a group in reverse scene order.
  165. .. _class_SceneTree_constant_GROUP_CALL_DEFERRED:
  166. .. rst-class:: classref-enumeration-constant
  167. :ref:`GroupCallFlags<enum_SceneTree_GroupCallFlags>` **GROUP_CALL_DEFERRED** = ``2``
  168. Call a group at the end of the current frame (process or physics).
  169. .. _class_SceneTree_constant_GROUP_CALL_UNIQUE:
  170. .. rst-class:: classref-enumeration-constant
  171. :ref:`GroupCallFlags<enum_SceneTree_GroupCallFlags>` **GROUP_CALL_UNIQUE** = ``4``
  172. Call a group only once even if the call is executed many times.
  173. \ **Note:** Arguments are not taken into account when deciding whether the call is unique or not. Therefore when the same method is called with different arguments, only the first call will be performed.
  174. .. rst-class:: classref-section-separator
  175. ----
  176. .. rst-class:: classref-descriptions-group
  177. Property Descriptions
  178. ---------------------
  179. .. _class_SceneTree_property_auto_accept_quit:
  180. .. rst-class:: classref-property
  181. :ref:`bool<class_bool>` **auto_accept_quit** = ``true``
  182. .. rst-class:: classref-property-setget
  183. - void **set_auto_accept_quit** **(** :ref:`bool<class_bool>` value **)**
  184. - :ref:`bool<class_bool>` **is_auto_accept_quit** **(** **)**
  185. If ``true``, the application automatically accepts quitting requests.
  186. For mobile platforms, see :ref:`quit_on_go_back<class_SceneTree_property_quit_on_go_back>`.
  187. .. rst-class:: classref-item-separator
  188. ----
  189. .. _class_SceneTree_property_current_scene:
  190. .. rst-class:: classref-property
  191. :ref:`Node<class_Node>` **current_scene**
  192. .. rst-class:: classref-property-setget
  193. - void **set_current_scene** **(** :ref:`Node<class_Node>` value **)**
  194. - :ref:`Node<class_Node>` **get_current_scene** **(** **)**
  195. Returns the root node of the currently running scene, regardless of its structure.
  196. \ **Warning:** Setting this directly might not work as expected, and will *not* add or remove any nodes from the tree, consider using :ref:`change_scene_to_file<class_SceneTree_method_change_scene_to_file>` or :ref:`change_scene_to_packed<class_SceneTree_method_change_scene_to_packed>` instead.
  197. .. rst-class:: classref-item-separator
  198. ----
  199. .. _class_SceneTree_property_debug_collisions_hint:
  200. .. rst-class:: classref-property
  201. :ref:`bool<class_bool>` **debug_collisions_hint** = ``false``
  202. .. rst-class:: classref-property-setget
  203. - void **set_debug_collisions_hint** **(** :ref:`bool<class_bool>` value **)**
  204. - :ref:`bool<class_bool>` **is_debugging_collisions_hint** **(** **)**
  205. If ``true``, collision shapes will be visible when running the game from the editor for debugging purposes.
  206. \ **Note:** This property is not designed to be changed at run-time. Changing the value of :ref:`debug_collisions_hint<class_SceneTree_property_debug_collisions_hint>` while the project is running will not have the desired effect.
  207. .. rst-class:: classref-item-separator
  208. ----
  209. .. _class_SceneTree_property_debug_navigation_hint:
  210. .. rst-class:: classref-property
  211. :ref:`bool<class_bool>` **debug_navigation_hint** = ``false``
  212. .. rst-class:: classref-property-setget
  213. - void **set_debug_navigation_hint** **(** :ref:`bool<class_bool>` value **)**
  214. - :ref:`bool<class_bool>` **is_debugging_navigation_hint** **(** **)**
  215. If ``true``, navigation polygons will be visible when running the game from the editor for debugging purposes.
  216. \ **Note:** This property is not designed to be changed at run-time. Changing the value of :ref:`debug_navigation_hint<class_SceneTree_property_debug_navigation_hint>` while the project is running will not have the desired effect.
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_SceneTree_property_debug_paths_hint:
  220. .. rst-class:: classref-property
  221. :ref:`bool<class_bool>` **debug_paths_hint** = ``false``
  222. .. rst-class:: classref-property-setget
  223. - void **set_debug_paths_hint** **(** :ref:`bool<class_bool>` value **)**
  224. - :ref:`bool<class_bool>` **is_debugging_paths_hint** **(** **)**
  225. If ``true``, curves from :ref:`Path2D<class_Path2D>` and :ref:`Path3D<class_Path3D>` nodes will be visible when running the game from the editor for debugging purposes.
  226. \ **Note:** This property is not designed to be changed at run-time. Changing the value of :ref:`debug_paths_hint<class_SceneTree_property_debug_paths_hint>` while the project is running will not have the desired effect.
  227. .. rst-class:: classref-item-separator
  228. ----
  229. .. _class_SceneTree_property_edited_scene_root:
  230. .. rst-class:: classref-property
  231. :ref:`Node<class_Node>` **edited_scene_root**
  232. .. rst-class:: classref-property-setget
  233. - void **set_edited_scene_root** **(** :ref:`Node<class_Node>` value **)**
  234. - :ref:`Node<class_Node>` **get_edited_scene_root** **(** **)**
  235. The root of the edited scene.
  236. .. rst-class:: classref-item-separator
  237. ----
  238. .. _class_SceneTree_property_multiplayer_poll:
  239. .. rst-class:: classref-property
  240. :ref:`bool<class_bool>` **multiplayer_poll** = ``true``
  241. .. rst-class:: classref-property-setget
  242. - void **set_multiplayer_poll_enabled** **(** :ref:`bool<class_bool>` value **)**
  243. - :ref:`bool<class_bool>` **is_multiplayer_poll_enabled** **(** **)**
  244. If ``true`` (default value), enables automatic polling of the :ref:`MultiplayerAPI<class_MultiplayerAPI>` for this SceneTree during :ref:`process_frame<class_SceneTree_signal_process_frame>`.
  245. If ``false``, you need to manually call :ref:`MultiplayerAPI.poll<class_MultiplayerAPI_method_poll>` to process network packets and deliver RPCs. This allows running RPCs in a different loop (e.g. physics, thread, specific time step) and for manual :ref:`Mutex<class_Mutex>` protection when accessing the :ref:`MultiplayerAPI<class_MultiplayerAPI>` from threads.
  246. .. rst-class:: classref-item-separator
  247. ----
  248. .. _class_SceneTree_property_paused:
  249. .. rst-class:: classref-property
  250. :ref:`bool<class_bool>` **paused** = ``false``
  251. .. rst-class:: classref-property-setget
  252. - void **set_pause** **(** :ref:`bool<class_bool>` value **)**
  253. - :ref:`bool<class_bool>` **is_paused** **(** **)**
  254. If ``true``, the **SceneTree** is paused. Doing so will have the following behavior:
  255. - 2D and 3D physics will be stopped. This includes signals and collision detection.
  256. - :ref:`Node._process<class_Node_private_method__process>`, :ref:`Node._physics_process<class_Node_private_method__physics_process>` and :ref:`Node._input<class_Node_private_method__input>` will not be called anymore in nodes.
  257. .. rst-class:: classref-item-separator
  258. ----
  259. .. _class_SceneTree_property_quit_on_go_back:
  260. .. rst-class:: classref-property
  261. :ref:`bool<class_bool>` **quit_on_go_back** = ``true``
  262. .. rst-class:: classref-property-setget
  263. - void **set_quit_on_go_back** **(** :ref:`bool<class_bool>` value **)**
  264. - :ref:`bool<class_bool>` **is_quit_on_go_back** **(** **)**
  265. If ``true``, the application quits automatically when navigating back (e.g. using the system "Back" button on Android).
  266. To handle 'Go Back' button when this option is disabled, use :ref:`DisplayServer.WINDOW_EVENT_GO_BACK_REQUEST<class_DisplayServer_constant_WINDOW_EVENT_GO_BACK_REQUEST>`.
  267. .. rst-class:: classref-item-separator
  268. ----
  269. .. _class_SceneTree_property_root:
  270. .. rst-class:: classref-property
  271. :ref:`Window<class_Window>` **root**
  272. .. rst-class:: classref-property-setget
  273. - :ref:`Window<class_Window>` **get_root** **(** **)**
  274. The **SceneTree**'s root :ref:`Window<class_Window>`.
  275. .. rst-class:: classref-section-separator
  276. ----
  277. .. rst-class:: classref-descriptions-group
  278. Method Descriptions
  279. -------------------
  280. .. _class_SceneTree_method_call_group:
  281. .. rst-class:: classref-method
  282. void **call_group** **(** :ref:`StringName<class_StringName>` group, :ref:`StringName<class_StringName>` method, ... **)** |vararg|
  283. Calls ``method`` on each member of the given group. You can pass arguments to ``method`` by specifying them at the end of the method call. If a node doesn't have the given method or the argument list does not match (either in count or in types), it will be skipped.
  284. \ **Note:** :ref:`call_group<class_SceneTree_method_call_group>` will call methods immediately on all members at once, which can cause stuttering if an expensive method is called on lots of members.
  285. .. rst-class:: classref-item-separator
  286. ----
  287. .. _class_SceneTree_method_call_group_flags:
  288. .. rst-class:: classref-method
  289. void **call_group_flags** **(** :ref:`int<class_int>` flags, :ref:`StringName<class_StringName>` group, :ref:`StringName<class_StringName>` method, ... **)** |vararg|
  290. Calls ``method`` on each member of the given group, respecting the given :ref:`GroupCallFlags<enum_SceneTree_GroupCallFlags>`. You can pass arguments to ``method`` by specifying them at the end of the method call. If a node doesn't have the given method or the argument list does not match (either in count or in types), it will be skipped.
  291. ::
  292. # Call the method in a deferred manner and in reverse order.
  293. get_tree().call_group_flags(SceneTree.GROUP_CALL_DEFERRED | SceneTree.GROUP_CALL_REVERSE)
  294. \ **Note:** Group call flags are used to control the method calling behavior. By default, methods will be called immediately in a way similar to :ref:`call_group<class_SceneTree_method_call_group>`. However, if the :ref:`GROUP_CALL_DEFERRED<class_SceneTree_constant_GROUP_CALL_DEFERRED>` flag is present in the ``flags`` argument, methods will be called at the end of the frame in a way similar to :ref:`Object.set_deferred<class_Object_method_set_deferred>`.
  295. .. rst-class:: classref-item-separator
  296. ----
  297. .. _class_SceneTree_method_change_scene_to_file:
  298. .. rst-class:: classref-method
  299. :ref:`Error<enum_@GlobalScope_Error>` **change_scene_to_file** **(** :ref:`String<class_String>` path **)**
  300. Changes the running scene to the one at the given ``path``, after loading it into a :ref:`PackedScene<class_PackedScene>` and creating a new instance.
  301. Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success, :ref:`@GlobalScope.ERR_CANT_OPEN<class_@GlobalScope_constant_ERR_CANT_OPEN>` if the ``path`` cannot be loaded into a :ref:`PackedScene<class_PackedScene>`, or :ref:`@GlobalScope.ERR_CANT_CREATE<class_@GlobalScope_constant_ERR_CANT_CREATE>` if that scene cannot be instantiated.
  302. \ **Note:** See :ref:`change_scene_to_packed<class_SceneTree_method_change_scene_to_packed>` for details on the order of operations.
  303. .. rst-class:: classref-item-separator
  304. ----
  305. .. _class_SceneTree_method_change_scene_to_packed:
  306. .. rst-class:: classref-method
  307. :ref:`Error<enum_@GlobalScope_Error>` **change_scene_to_packed** **(** :ref:`PackedScene<class_PackedScene>` packed_scene **)**
  308. Changes the running scene to a new instance of the given :ref:`PackedScene<class_PackedScene>` (which must be valid).
  309. Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success, :ref:`@GlobalScope.ERR_CANT_CREATE<class_@GlobalScope_constant_ERR_CANT_CREATE>` if the scene cannot be instantiated, or :ref:`@GlobalScope.ERR_INVALID_PARAMETER<class_@GlobalScope_constant_ERR_INVALID_PARAMETER>` if the scene is invalid.
  310. \ **Note:** Operations happen in the following order when :ref:`change_scene_to_packed<class_SceneTree_method_change_scene_to_packed>` is called:
  311. 1. The current scene node is immediately removed from the tree. From that point, :ref:`Node.get_tree<class_Node_method_get_tree>` called on the current (outgoing) scene will return ``null``. :ref:`current_scene<class_SceneTree_property_current_scene>` will be ``null``, too, because the new scene is not available yet.
  312. 2. At the end of the frame, the formerly current scene, already removed from the tree, will be deleted (freed from memory) and then the new scene will be instantiated and added to the tree. :ref:`Node.get_tree<class_Node_method_get_tree>` and :ref:`current_scene<class_SceneTree_property_current_scene>` will be back to working as usual.
  313. This ensures that both scenes aren't running at the same time, while still freeing the previous scene in a safe way similar to :ref:`Node.queue_free<class_Node_method_queue_free>`.
  314. .. rst-class:: classref-item-separator
  315. ----
  316. .. _class_SceneTree_method_create_timer:
  317. .. rst-class:: classref-method
  318. :ref:`SceneTreeTimer<class_SceneTreeTimer>` **create_timer** **(** :ref:`float<class_float>` time_sec, :ref:`bool<class_bool>` process_always=true, :ref:`bool<class_bool>` process_in_physics=false, :ref:`bool<class_bool>` ignore_time_scale=false **)**
  319. Returns a :ref:`SceneTreeTimer<class_SceneTreeTimer>` which will emit :ref:`SceneTreeTimer.timeout<class_SceneTreeTimer_signal_timeout>` after the given time in seconds elapsed in this **SceneTree**.
  320. If ``process_always`` is set to ``false``, pausing the **SceneTree** will also pause the timer.
  321. If ``process_in_physics`` is set to ``true``, will update the :ref:`SceneTreeTimer<class_SceneTreeTimer>` during the physics frame instead of the process frame (fixed framerate processing).
  322. If ``ignore_time_scale`` is set to ``true``, will ignore :ref:`Engine.time_scale<class_Engine_property_time_scale>` and update the :ref:`SceneTreeTimer<class_SceneTreeTimer>` with the actual frame delta.
  323. Commonly used to create a one-shot delay timer as in the following example:
  324. .. tabs::
  325. .. code-tab:: gdscript
  326. func some_function():
  327. print("start")
  328. await get_tree().create_timer(1.0).timeout
  329. print("end")
  330. .. code-tab:: csharp
  331. public async Task SomeFunction()
  332. {
  333. GD.Print("start");
  334. await ToSignal(GetTree().CreateTimer(1.0f), SceneTreeTimer.SignalName.Timeout);
  335. GD.Print("end");
  336. }
  337. The timer will be automatically freed after its time elapses.
  338. \ **Note:** The timer is processed after all of the nodes in the current frame, i.e. node's :ref:`Node._process<class_Node_private_method__process>` method would be called before the timer (or :ref:`Node._physics_process<class_Node_private_method__physics_process>` if ``process_in_physics`` is set to ``true``).
  339. .. rst-class:: classref-item-separator
  340. ----
  341. .. _class_SceneTree_method_create_tween:
  342. .. rst-class:: classref-method
  343. :ref:`Tween<class_Tween>` **create_tween** **(** **)**
  344. Creates and returns a new :ref:`Tween<class_Tween>`. The Tween will start automatically on the next process frame or physics frame (depending on :ref:`TweenProcessMode<enum_Tween_TweenProcessMode>`).
  345. \ **Note:** When creating a :ref:`Tween<class_Tween>` using this method, the :ref:`Tween<class_Tween>` will not be tied to the :ref:`Node<class_Node>` that called it. It will continue to animate even if the :ref:`Node<class_Node>` is freed, but it will automatically finish if there's nothing left to animate. If you want the :ref:`Tween<class_Tween>` to be automatically killed when the :ref:`Node<class_Node>` is freed, use :ref:`Node.create_tween<class_Node_method_create_tween>` or :ref:`Tween.bind_node<class_Tween_method_bind_node>`.
  346. .. rst-class:: classref-item-separator
  347. ----
  348. .. _class_SceneTree_method_get_first_node_in_group:
  349. .. rst-class:: classref-method
  350. :ref:`Node<class_Node>` **get_first_node_in_group** **(** :ref:`StringName<class_StringName>` group **)**
  351. Returns the first node in the specified group, or ``null`` if the group is empty or does not exist.
  352. .. rst-class:: classref-item-separator
  353. ----
  354. .. _class_SceneTree_method_get_frame:
  355. .. rst-class:: classref-method
  356. :ref:`int<class_int>` **get_frame** **(** **)** |const|
  357. Returns the current frame number, i.e. the total frame count since the application started.
  358. .. rst-class:: classref-item-separator
  359. ----
  360. .. _class_SceneTree_method_get_multiplayer:
  361. .. rst-class:: classref-method
  362. :ref:`MultiplayerAPI<class_MultiplayerAPI>` **get_multiplayer** **(** :ref:`NodePath<class_NodePath>` for_path=NodePath("") **)** |const|
  363. Searches for the :ref:`MultiplayerAPI<class_MultiplayerAPI>` configured for the given path, if one does not exist it searches the parent paths until one is found. If the path is empty, or none is found, the default one is returned. See :ref:`set_multiplayer<class_SceneTree_method_set_multiplayer>`.
  364. .. rst-class:: classref-item-separator
  365. ----
  366. .. _class_SceneTree_method_get_node_count:
  367. .. rst-class:: classref-method
  368. :ref:`int<class_int>` **get_node_count** **(** **)** |const|
  369. Returns the number of nodes in this **SceneTree**.
  370. .. rst-class:: classref-item-separator
  371. ----
  372. .. _class_SceneTree_method_get_nodes_in_group:
  373. .. rst-class:: classref-method
  374. :ref:`Node[]<class_Node>` **get_nodes_in_group** **(** :ref:`StringName<class_StringName>` group **)**
  375. Returns a list of all nodes assigned to the given group.
  376. .. rst-class:: classref-item-separator
  377. ----
  378. .. _class_SceneTree_method_get_processed_tweens:
  379. .. rst-class:: classref-method
  380. :ref:`Tween[]<class_Tween>` **get_processed_tweens** **(** **)**
  381. Returns an array of currently existing :ref:`Tween<class_Tween>`\ s in the **SceneTree** (both running and paused).
  382. .. rst-class:: classref-item-separator
  383. ----
  384. .. _class_SceneTree_method_has_group:
  385. .. rst-class:: classref-method
  386. :ref:`bool<class_bool>` **has_group** **(** :ref:`StringName<class_StringName>` name **)** |const|
  387. Returns ``true`` if the given group exists.
  388. A group exists if any :ref:`Node<class_Node>` in the tree belongs to it (see :ref:`Node.add_to_group<class_Node_method_add_to_group>`). Groups without nodes are removed automatically.
  389. .. rst-class:: classref-item-separator
  390. ----
  391. .. _class_SceneTree_method_notify_group:
  392. .. rst-class:: classref-method
  393. void **notify_group** **(** :ref:`StringName<class_StringName>` group, :ref:`int<class_int>` notification **)**
  394. Sends the given notification to all members of the ``group``.
  395. \ **Note:** :ref:`notify_group<class_SceneTree_method_notify_group>` will immediately notify all members at once, which can cause stuttering if an expensive method is called as a result of sending the notification to lots of members.
  396. .. rst-class:: classref-item-separator
  397. ----
  398. .. _class_SceneTree_method_notify_group_flags:
  399. .. rst-class:: classref-method
  400. void **notify_group_flags** **(** :ref:`int<class_int>` call_flags, :ref:`StringName<class_StringName>` group, :ref:`int<class_int>` notification **)**
  401. Sends the given notification to all members of the ``group``, respecting the given :ref:`GroupCallFlags<enum_SceneTree_GroupCallFlags>`.
  402. \ **Note:** Group call flags are used to control the notification sending behavior. By default, notifications will be sent immediately in a way similar to :ref:`notify_group<class_SceneTree_method_notify_group>`. However, if the :ref:`GROUP_CALL_DEFERRED<class_SceneTree_constant_GROUP_CALL_DEFERRED>` flag is present in the ``call_flags`` argument, notifications will be sent at the end of the current frame in a way similar to using ``Object.call_deferred("notification", ...)``.
  403. .. rst-class:: classref-item-separator
  404. ----
  405. .. _class_SceneTree_method_queue_delete:
  406. .. rst-class:: classref-method
  407. void **queue_delete** **(** :ref:`Object<class_Object>` obj **)**
  408. Queues the given object for deletion, delaying the call to :ref:`Object.free<class_Object_method_free>` to the end of the current frame.
  409. .. rst-class:: classref-item-separator
  410. ----
  411. .. _class_SceneTree_method_quit:
  412. .. rst-class:: classref-method
  413. void **quit** **(** :ref:`int<class_int>` exit_code=0 **)**
  414. Quits the application at the end of the current iteration. Argument ``exit_code`` can optionally be given (defaulting to 0) to customize the exit status code.
  415. By convention, an exit code of ``0`` indicates success whereas a non-zero exit code indicates an error.
  416. For portability reasons, the exit code should be set between 0 and 125 (inclusive).
  417. \ **Note:** On iOS this method doesn't work. Instead, as recommended by the iOS Human Interface Guidelines, the user is expected to close apps via the Home button.
  418. .. rst-class:: classref-item-separator
  419. ----
  420. .. _class_SceneTree_method_reload_current_scene:
  421. .. rst-class:: classref-method
  422. :ref:`Error<enum_@GlobalScope_Error>` **reload_current_scene** **(** **)**
  423. Reloads the currently active scene.
  424. Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success, :ref:`@GlobalScope.ERR_UNCONFIGURED<class_@GlobalScope_constant_ERR_UNCONFIGURED>` if no :ref:`current_scene<class_SceneTree_property_current_scene>` was defined yet, :ref:`@GlobalScope.ERR_CANT_OPEN<class_@GlobalScope_constant_ERR_CANT_OPEN>` if :ref:`current_scene<class_SceneTree_property_current_scene>` cannot be loaded into a :ref:`PackedScene<class_PackedScene>`, or :ref:`@GlobalScope.ERR_CANT_CREATE<class_@GlobalScope_constant_ERR_CANT_CREATE>` if the scene cannot be instantiated.
  425. .. rst-class:: classref-item-separator
  426. ----
  427. .. _class_SceneTree_method_set_group:
  428. .. rst-class:: classref-method
  429. void **set_group** **(** :ref:`StringName<class_StringName>` group, :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)**
  430. Sets the given ``property`` to ``value`` on all members of the given group.
  431. \ **Note:** :ref:`set_group<class_SceneTree_method_set_group>` will set the property immediately on all members at once, which can cause stuttering if a property with an expensive setter is set on lots of members.
  432. .. rst-class:: classref-item-separator
  433. ----
  434. .. _class_SceneTree_method_set_group_flags:
  435. .. rst-class:: classref-method
  436. void **set_group_flags** **(** :ref:`int<class_int>` call_flags, :ref:`StringName<class_StringName>` group, :ref:`String<class_String>` property, :ref:`Variant<class_Variant>` value **)**
  437. Sets the given ``property`` to ``value`` on all members of the given group, respecting the given :ref:`GroupCallFlags<enum_SceneTree_GroupCallFlags>`.
  438. \ **Note:** Group call flags are used to control the property setting behavior. By default, properties will be set immediately in a way similar to :ref:`set_group<class_SceneTree_method_set_group>`. However, if the :ref:`GROUP_CALL_DEFERRED<class_SceneTree_constant_GROUP_CALL_DEFERRED>` flag is present in the ``call_flags`` argument, properties will be set at the end of the frame in a way similar to :ref:`Object.call_deferred<class_Object_method_call_deferred>`.
  439. .. rst-class:: classref-item-separator
  440. ----
  441. .. _class_SceneTree_method_set_multiplayer:
  442. .. rst-class:: classref-method
  443. void **set_multiplayer** **(** :ref:`MultiplayerAPI<class_MultiplayerAPI>` multiplayer, :ref:`NodePath<class_NodePath>` root_path=NodePath("") **)**
  444. Sets a custom :ref:`MultiplayerAPI<class_MultiplayerAPI>` with the given ``root_path`` (controlling also the relative subpaths), or override the default one if ``root_path`` is empty.
  445. \ **Note:** No :ref:`MultiplayerAPI<class_MultiplayerAPI>` must be configured for the subpath containing ``root_path``, nested custom multiplayers are not allowed. I.e. if one is configured for ``"/root/Foo"`` setting one for ``"/root/Foo/Bar"`` will cause an error.
  446. .. rst-class:: classref-item-separator
  447. ----
  448. .. _class_SceneTree_method_unload_current_scene:
  449. .. rst-class:: classref-method
  450. void **unload_current_scene** **(** **)**
  451. If a current scene is loaded, calling this method will unload it.
  452. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  453. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  454. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  455. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  456. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  457. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  458. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`