class_scenetree.rst 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the SceneTree.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_SceneTree:
  5. SceneTree
  6. =========
  7. **Inherits:** :ref:`MainLoop<class_mainloop>` **<** :ref:`Object<class_object>`
  8. **Category:** Core
  9. Brief Description
  10. -----------------
  11. SceneTree manages a hierarchy of nodes.
  12. Member Functions
  13. ----------------
  14. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  15. | :ref:`Variant<class_variant>` | :ref:`call_group<class_SceneTree_call_group>` **(** :ref:`String<class_string>` group, :ref:`String<class_string>` method **)** vararg |
  16. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  17. | :ref:`Variant<class_variant>` | :ref:`call_group_flags<class_SceneTree_call_group_flags>` **(** :ref:`int<class_int>` flags, :ref:`String<class_string>` group, :ref:`String<class_string>` method **)** vararg |
  18. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`int<class_int>` | :ref:`change_scene<class_SceneTree_change_scene>` **(** :ref:`String<class_string>` path **)** |
  20. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`int<class_int>` | :ref:`change_scene_to<class_SceneTree_change_scene_to>` **(** :ref:`PackedScene<class_packedscene>` packed_scene **)** |
  22. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`SceneTreeTimer<class_scenetreetimer>` | :ref:`create_timer<class_SceneTree_create_timer>` **(** :ref:`float<class_float>` time_sec, :ref:`bool<class_bool>` pause_mode_process=true **)** |
  24. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`int<class_int>` | :ref:`get_frame<class_SceneTree_get_frame>` **(** **)** const |
  26. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`PoolIntArray<class_poolintarray>` | :ref:`get_network_connected_peers<class_SceneTree_get_network_connected_peers>` **(** **)** const |
  28. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`int<class_int>` | :ref:`get_network_unique_id<class_SceneTree_get_network_unique_id>` **(** **)** const |
  30. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`int<class_int>` | :ref:`get_node_count<class_SceneTree_get_node_count>` **(** **)** const |
  32. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Array<class_array>` | :ref:`get_nodes_in_group<class_SceneTree_get_nodes_in_group>` **(** :ref:`String<class_string>` group **)** |
  34. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`int<class_int>` | :ref:`get_rpc_sender_id<class_SceneTree_get_rpc_sender_id>` **(** **)** const |
  36. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`bool<class_bool>` | :ref:`has_group<class_SceneTree_has_group>` **(** :ref:`String<class_string>` name **)** const |
  38. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`bool<class_bool>` | :ref:`has_network_peer<class_SceneTree_has_network_peer>` **(** **)** const |
  40. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`bool<class_bool>` | :ref:`is_input_handled<class_SceneTree_is_input_handled>` **(** **)** |
  42. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`is_network_server<class_SceneTree_is_network_server>` **(** **)** const |
  44. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`notify_group<class_SceneTree_notify_group>` **(** :ref:`String<class_string>` group, :ref:`int<class_int>` notification **)** |
  46. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`notify_group_flags<class_SceneTree_notify_group_flags>` **(** :ref:`int<class_int>` call_flags, :ref:`String<class_string>` group, :ref:`int<class_int>` notification **)** |
  48. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`queue_delete<class_SceneTree_queue_delete>` **(** :ref:`Object<class_object>` obj **)** |
  50. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`quit<class_SceneTree_quit>` **(** **)** |
  52. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`int<class_int>` | :ref:`reload_current_scene<class_SceneTree_reload_current_scene>` **(** **)** |
  54. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`set_auto_accept_quit<class_SceneTree_set_auto_accept_quit>` **(** :ref:`bool<class_bool>` enabled **)** |
  56. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`set_group<class_SceneTree_set_group>` **(** :ref:`String<class_string>` group, :ref:`String<class_string>` property, :ref:`Variant<class_variant>` value **)** |
  58. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`set_group_flags<class_SceneTree_set_group_flags>` **(** :ref:`int<class_int>` call_flags, :ref:`String<class_string>` group, :ref:`String<class_string>` property, :ref:`Variant<class_variant>` value **)** |
  60. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`set_input_as_handled<class_SceneTree_set_input_as_handled>` **(** **)** |
  62. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`set_quit_on_go_back<class_SceneTree_set_quit_on_go_back>` **(** :ref:`bool<class_bool>` enabled **)** |
  64. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`set_screen_stretch<class_SceneTree_set_screen_stretch>` **(** :ref:`int<class_int>` mode, :ref:`int<class_int>` aspect, :ref:`Vector2<class_vector2>` minsize, :ref:`float<class_float>` shrink=1 **)** |
  66. +----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. Signals
  68. -------
  69. .. _class_SceneTree_connected_to_server:
  70. - **connected_to_server** **(** **)**
  71. Emitted whenever this SceneTree's :ref:`network_peer<class_SceneTree_network_peer>` successfully connected to a server. Only emitted on clients.
  72. .. _class_SceneTree_connection_failed:
  73. - **connection_failed** **(** **)**
  74. Emitted whenever this SceneTree's :ref:`network_peer<class_SceneTree_network_peer>` fails to establish a connection to a server. Only emitted on clients.
  75. .. _class_SceneTree_files_dropped:
  76. - **files_dropped** **(** :ref:`PoolStringArray<class_poolstringarray>` files, :ref:`int<class_int>` screen **)**
  77. Emitted whenever files are drag-and-dropped onto the window.
  78. .. _class_SceneTree_idle_frame:
  79. - **idle_frame** **(** **)**
  80. Emitted immediately before :ref:`Node._process<class_Node__process>` is called on every node in the SceneTree.
  81. .. _class_SceneTree_network_peer_connected:
  82. - **network_peer_connected** **(** :ref:`int<class_int>` id **)**
  83. Emitted whenever this SceneTree's :ref:`network_peer<class_SceneTree_network_peer>` connects with a new peer. ID is the peer ID of the new peer. Clients get notified when other clients connect to the same server. Upon connecting to a server, a client also receives this signal for the server (with ID being 1).
  84. .. _class_SceneTree_network_peer_disconnected:
  85. - **network_peer_disconnected** **(** :ref:`int<class_int>` id **)**
  86. Emitted whenever this SceneTree's :ref:`network_peer<class_SceneTree_network_peer>` disconnects from a peer. Clients get notified when other clients disconnect from the same server.
  87. .. _class_SceneTree_node_added:
  88. - **node_added** **(** :ref:`Object<class_object>` node **)**
  89. Emitted whenever a node is added to the SceneTree.
  90. .. _class_SceneTree_node_configuration_warning_changed:
  91. - **node_configuration_warning_changed** **(** :ref:`Object<class_object>` node **)**
  92. Emitted when a node's configuration changed. Only emitted in tool mode.
  93. .. _class_SceneTree_node_removed:
  94. - **node_removed** **(** :ref:`Object<class_object>` node **)**
  95. Emitted whenever a node is removed from the SceneTree.
  96. .. _class_SceneTree_physics_frame:
  97. - **physics_frame** **(** **)**
  98. Emitted immediately before :ref:`Node._physics_process<class_Node__physics_process>` is called on every node in the SceneTree.
  99. .. _class_SceneTree_screen_resized:
  100. - **screen_resized** **(** **)**
  101. Emitted whenever the screen resolution (fullscreen) or window size (windowed) changes.
  102. .. _class_SceneTree_server_disconnected:
  103. - **server_disconnected** **(** **)**
  104. Emitted whenever this SceneTree's :ref:`network_peer<class_SceneTree_network_peer>` disconnected from server. Only emitted on clients.
  105. .. _class_SceneTree_tree_changed:
  106. - **tree_changed** **(** **)**
  107. Emitted whenever the SceneTree hierarchy changed (children being moved or renamed, etc.).
  108. Member Variables
  109. ----------------
  110. .. _class_SceneTree_current_scene:
  111. - :ref:`Node<class_node>` **current_scene** - The current scene.
  112. .. _class_SceneTree_debug_collisions_hint:
  113. - :ref:`bool<class_bool>` **debug_collisions_hint**
  114. .. _class_SceneTree_debug_navigation_hint:
  115. - :ref:`bool<class_bool>` **debug_navigation_hint**
  116. .. _class_SceneTree_edited_scene_root:
  117. - :ref:`Node<class_node>` **edited_scene_root** - The root of the edited scene.
  118. .. _class_SceneTree_network_peer:
  119. - :ref:`NetworkedMultiplayerPeer<class_networkedmultiplayerpeer>` **network_peer** - The peer object to handle the RPC system (effectively enabling networking when set). Depending on the peer itself, the SceneTree will become a network server (check with :ref:`is_network_server()<class_SceneTree_is_network_server()>`) and will set root node's network mode to master (see NETWORK_MODE\_\* constants in :ref:`Node<class_node>`), or it will become a regular peer with root node set to slave. All child nodes are set to inherit the network mode by default. Handling of networking-related events (connection, disconnection, new clients) is done by connecting to SceneTree's signals.
  120. .. _class_SceneTree_paused:
  121. - :ref:`bool<class_bool>` **paused** - If ``true`` the SceneTree is paused.
  122. .. _class_SceneTree_refuse_new_network_connections:
  123. - :ref:`bool<class_bool>` **refuse_new_network_connections** - If ``true`` the SceneTree's :ref:`network_peer<class_SceneTree_network_peer>` refuses new incoming connections.
  124. .. _class_SceneTree_root:
  125. - :ref:`Viewport<class_viewport>` **root** - The SceneTree's :ref:`Viewport<class_viewport>`.
  126. .. _class_SceneTree_use_font_oversampling:
  127. - :ref:`bool<class_bool>` **use_font_oversampling** - If ``true`` font oversampling is used.
  128. Enums
  129. -----
  130. .. _enum_SceneTree_GroupCallFlags:
  131. enum **GroupCallFlags**
  132. - **GROUP_CALL_DEFAULT** = **0** --- Call a group with no flags (default).
  133. - **GROUP_CALL_REVERSE** = **1** --- Call a group in reverse scene order.
  134. - **GROUP_CALL_REALTIME** = **2** --- Call a group immediately (calls are normally made on idle).
  135. - **GROUP_CALL_UNIQUE** = **4** --- Call a group only once even if the call is executed many times.
  136. .. _enum_SceneTree_StretchMode:
  137. enum **StretchMode**
  138. - **STRETCH_MODE_DISABLED** = **0**
  139. - **STRETCH_MODE_2D** = **1**
  140. - **STRETCH_MODE_VIEWPORT** = **2**
  141. .. _enum_SceneTree_StretchAspect:
  142. enum **StretchAspect**
  143. - **STRETCH_ASPECT_IGNORE** = **0**
  144. - **STRETCH_ASPECT_KEEP** = **1**
  145. - **STRETCH_ASPECT_KEEP_WIDTH** = **2**
  146. - **STRETCH_ASPECT_KEEP_HEIGHT** = **3**
  147. - **STRETCH_ASPECT_EXPAND** = **4**
  148. Description
  149. -----------
  150. 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. 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. a "enemy" group. You can then iterate these groups or even call methods and set properties on all the group's members at once.
  151. Member Function Description
  152. ---------------------------
  153. .. _class_SceneTree_call_group:
  154. - :ref:`Variant<class_variant>` **call_group** **(** :ref:`String<class_string>` group, :ref:`String<class_string>` method **)** vararg
  155. Calls ``method`` on each member of the given group.
  156. .. _class_SceneTree_call_group_flags:
  157. - :ref:`Variant<class_variant>` **call_group_flags** **(** :ref:`int<class_int>` flags, :ref:`String<class_string>` group, :ref:`String<class_string>` method **)** vararg
  158. Calls ``method`` on each member of the given group, respecting the given enum GROUP_CALL flags.
  159. .. _class_SceneTree_change_scene:
  160. - :ref:`int<class_int>` **change_scene** **(** :ref:`String<class_string>` path **)**
  161. Changes to the scene at the given ``path``.
  162. .. _class_SceneTree_change_scene_to:
  163. - :ref:`int<class_int>` **change_scene_to** **(** :ref:`PackedScene<class_packedscene>` packed_scene **)**
  164. Changes to the given :ref:`PackedScene<class_packedscene>`.
  165. .. _class_SceneTree_create_timer:
  166. - :ref:`SceneTreeTimer<class_scenetreetimer>` **create_timer** **(** :ref:`float<class_float>` time_sec, :ref:`bool<class_bool>` pause_mode_process=true **)**
  167. Returns a :ref:`SceneTreeTimer<class_scenetreetimer>` which will :ref:`SceneTreeTimer.timeout<class_SceneTreeTimer_timeout>` after the given time in seconds elapsed in this SceneTree. If ``pause_mode_process`` is set to false, pausing the SceneTree will also pause the timer.
  168. .. _class_SceneTree_get_frame:
  169. - :ref:`int<class_int>` **get_frame** **(** **)** const
  170. .. _class_SceneTree_get_network_connected_peers:
  171. - :ref:`PoolIntArray<class_poolintarray>` **get_network_connected_peers** **(** **)** const
  172. Returns the peer IDs of all connected peers of this SceneTree's :ref:`network_peer<class_SceneTree_network_peer>`.
  173. .. _class_SceneTree_get_network_unique_id:
  174. - :ref:`int<class_int>` **get_network_unique_id** **(** **)** const
  175. Returns the unique peer ID of this SceneTree's :ref:`network_peer<class_SceneTree_network_peer>`.
  176. .. _class_SceneTree_get_node_count:
  177. - :ref:`int<class_int>` **get_node_count** **(** **)** const
  178. Returns the number of nodes in this SceneTree.
  179. .. _class_SceneTree_get_nodes_in_group:
  180. - :ref:`Array<class_array>` **get_nodes_in_group** **(** :ref:`String<class_string>` group **)**
  181. Returns all nodes assigned to the given group.
  182. .. _class_SceneTree_get_rpc_sender_id:
  183. - :ref:`int<class_int>` **get_rpc_sender_id** **(** **)** const
  184. Returns the sender's peer ID for the most recently received RPC call.
  185. .. _class_SceneTree_has_group:
  186. - :ref:`bool<class_bool>` **has_group** **(** :ref:`String<class_string>` name **)** const
  187. Returns ``true`` if the given group exists.
  188. .. _class_SceneTree_has_network_peer:
  189. - :ref:`bool<class_bool>` **has_network_peer** **(** **)** const
  190. Returns ``true`` if there is a :ref:`network_peer<class_SceneTree_network_peer>` set.
  191. .. _class_SceneTree_is_input_handled:
  192. - :ref:`bool<class_bool>` **is_input_handled** **(** **)**
  193. Returns ``true`` if the most recent InputEvent was marked as handled with :ref:`set_input_as_handled<class_SceneTree_set_input_as_handled>`.
  194. .. _class_SceneTree_is_network_server:
  195. - :ref:`bool<class_bool>` **is_network_server** **(** **)** const
  196. Returns ``true`` if this SceneTree's :ref:`network_peer<class_SceneTree_network_peer>` is in server mode (listening for connections).
  197. .. _class_SceneTree_notify_group:
  198. - void **notify_group** **(** :ref:`String<class_string>` group, :ref:`int<class_int>` notification **)**
  199. Sends the given notification to all members of the ``group``.
  200. .. _class_SceneTree_notify_group_flags:
  201. - void **notify_group_flags** **(** :ref:`int<class_int>` call_flags, :ref:`String<class_string>` group, :ref:`int<class_int>` notification **)**
  202. Sends the given notification to all members of the ``group``, respecting the given enum GROUP_CALL flags.
  203. .. _class_SceneTree_queue_delete:
  204. - void **queue_delete** **(** :ref:`Object<class_object>` obj **)**
  205. Queues the given object for deletion, delaying the call to :ref:`Object.free<class_Object_free>` to after the current frame.
  206. .. _class_SceneTree_quit:
  207. - void **quit** **(** **)**
  208. Quits the application.
  209. .. _class_SceneTree_reload_current_scene:
  210. - :ref:`int<class_int>` **reload_current_scene** **(** **)**
  211. Reloads the currently active scene.
  212. .. _class_SceneTree_set_auto_accept_quit:
  213. - void **set_auto_accept_quit** **(** :ref:`bool<class_bool>` enabled **)**
  214. If ``true`` the application automatically accepts quitting.
  215. .. _class_SceneTree_set_group:
  216. - void **set_group** **(** :ref:`String<class_string>` group, :ref:`String<class_string>` property, :ref:`Variant<class_variant>` value **)**
  217. Sets the given ``property`` to ``value`` on all members of the given group.
  218. .. _class_SceneTree_set_group_flags:
  219. - void **set_group_flags** **(** :ref:`int<class_int>` call_flags, :ref:`String<class_string>` group, :ref:`String<class_string>` property, :ref:`Variant<class_variant>` value **)**
  220. Sets the given ``property`` to ``value`` on all members of the given group, respecting the given enum GROUP_CALL flags.
  221. .. _class_SceneTree_set_input_as_handled:
  222. - void **set_input_as_handled** **(** **)**
  223. Marks the most recent input event as handled.
  224. .. _class_SceneTree_set_quit_on_go_back:
  225. - void **set_quit_on_go_back** **(** :ref:`bool<class_bool>` enabled **)**
  226. If ``true`` the application quits automatically on going back (e.g. on Android).
  227. .. _class_SceneTree_set_screen_stretch:
  228. - void **set_screen_stretch** **(** :ref:`int<class_int>` mode, :ref:`int<class_int>` aspect, :ref:`Vector2<class_vector2>` minsize, :ref:`float<class_float>` shrink=1 **)**
  229. Configures screen stretching to the given enum StretchMode, enum StretchAspect, minimum size and ``shrink``.