SceneTree

Inherits: MainLoop < Object

Category: Core

Brief Description

SceneTree manages a hierarchy of nodes.

Member Functions

Variant call_group ( String group, String method ) vararg
Variant call_group_flags ( int flags, String group, String method ) vararg
Error change_scene ( String path )
Error change_scene_to ( PackedScene packed_scene )
SceneTreeTimer create_timer ( float time_sec, bool pause_mode_process=true )
int get_frame ( ) const
PoolIntArray get_network_connected_peers ( ) const
int get_network_unique_id ( ) const
int get_node_count ( ) const
Array get_nodes_in_group ( String group )
int get_rpc_sender_id ( ) const
bool has_group ( String name ) const
bool has_network_peer ( ) const
bool is_input_handled ( )
bool is_network_server ( ) const
void notify_group ( String group, int notification )
void notify_group_flags ( int call_flags, String group, int notification )
void queue_delete ( Object obj )
void quit ( )
Error reload_current_scene ( )
void set_auto_accept_quit ( bool enabled )
void set_group ( String group, String property, Variant value )
void set_group_flags ( int call_flags, String group, String property, Variant value )
void set_input_as_handled ( )
void set_quit_on_go_back ( bool enabled )
void set_screen_stretch ( StretchMode mode, StretchAspect aspect, Vector2 minsize, float shrink=1 )

Signals

  • connected_to_server ( )

Emitted whenever this SceneTree’s network_peer successfully connected to a server. Only emitted on clients.

  • connection_failed ( )

Emitted whenever this SceneTree’s network_peer fails to establish a connection to a server. Only emitted on clients.

Emitted whenever files are drag-and-dropped onto the window.

  • idle_frame ( )

Emitted immediately before Node._process is called on every node in the SceneTree.

  • network_peer_connected ( int id )

Emitted whenever this SceneTree’s 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).

  • network_peer_disconnected ( int id )

Emitted whenever this SceneTree’s network_peer disconnects from a peer. Clients get notified when other clients disconnect from the same server.

Emitted whenever a node is added to the SceneTree.

  • node_configuration_warning_changed ( Object node )

Emitted when a node’s configuration changed. Only emitted in tool mode.

  • node_removed ( Object node )

Emitted whenever a node is removed from the SceneTree.

  • physics_frame ( )

Emitted immediately before Node._physics_process is called on every node in the SceneTree.

  • screen_resized ( )

Emitted whenever the screen resolution (fullscreen) or window size (windowed) changes.

  • server_disconnected ( )

Emitted whenever this SceneTree’s network_peer disconnected from server. Only emitted on clients.

  • tree_changed ( )

Emitted whenever the SceneTree hierarchy changed (children being moved or renamed, etc.).

Member Variables

  • Node current_scene - The current scene.
  • bool debug_collisions_hint
  • bool debug_navigation_hint
  • Node edited_scene_root - The root of the edited scene.
  • MultiplayerAPI multiplayer - The default MultiplayerAPI instance for this SceneTree.
  • bool multiplayer_poll - If true (default) enable the automatic polling of the MultiplayerAPI for this SceneTree during idle_frame.

When false you need to manually call MultiplayerAPI.poll for processing network packets and delivering RPCs/RSETs. This allows to run RPCs/RSETs in a different loop (e.g. physics, thread, specific time step) and for manual Mutex protecion when accessing the MultiplayerAPI from threads.

  • 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 is_network_server()) and will set root node’s network mode to master (see NETWORK_MODE_* constants in 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.
  • bool paused - If true the SceneTree is paused.
  • bool refuse_new_network_connections - If true the SceneTree’s network_peer refuses new incoming connections.
  • Viewport root - The SceneTree’s Viewport.
  • bool use_font_oversampling - If true font oversampling is used.

Enums

enum GroupCallFlags

  • GROUP_CALL_DEFAULT = 0 — Call a group with no flags (default).
  • GROUP_CALL_REVERSE = 1 — Call a group in reverse scene order.
  • GROUP_CALL_REALTIME = 2 — Call a group immediately (calls are normally made on idle).
  • GROUP_CALL_UNIQUE = 4 — Call a group only once even if the call is executed many times.

enum StretchMode

  • STRETCH_MODE_DISABLED = 0
  • STRETCH_MODE_2D = 1
  • STRETCH_MODE_VIEWPORT = 2

enum StretchAspect

  • STRETCH_ASPECT_IGNORE = 0
  • STRETCH_ASPECT_KEEP = 1
  • STRETCH_ASPECT_KEEP_WIDTH = 2
  • STRETCH_ASPECT_KEEP_HEIGHT = 3
  • STRETCH_ASPECT_EXPAND = 4

Description

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.

Member Function Description

Calls method on each member of the given group.

Calls method on each member of the given group, respecting the given GroupCallFlags.

Changes to the scene at the given path.

Changes to the given PackedScene.

Returns a SceneTreeTimer which will 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.

  • int get_frame ( ) const

Returns the peer IDs of all connected peers of this SceneTree’s network_peer.

  • int get_network_unique_id ( ) const

Returns the unique peer ID of this SceneTree’s network_peer.

  • int get_node_count ( ) const

Returns the number of nodes in this SceneTree.

Returns all nodes assigned to the given group.

  • int get_rpc_sender_id ( ) const

Returns the sender’s peer ID for the most recently received RPC call.

Returns true if the given group exists.

  • bool has_network_peer ( ) const

Returns true if there is a network_peer set.

  • bool is_input_handled ( )

Returns true if the most recent InputEvent was marked as handled with set_input_as_handled.

  • bool is_network_server ( ) const

Returns true if this SceneTree’s network_peer is in server mode (listening for connections).

  • void notify_group ( String group, int notification )

Sends the given notification to all members of the group.

  • void notify_group_flags ( int call_flags, String group, int notification )

Sends the given notification to all members of the group, respecting the given GroupCallFlags.

  • void queue_delete ( Object obj )

Queues the given object for deletion, delaying the call to Object.free to after the current frame.

  • void quit ( )

Quits the application.

  • Error reload_current_scene ( )

Reloads the currently active scene.

  • void set_auto_accept_quit ( bool enabled )

If true the application automatically accepts quitting.

Sets the given property to value on all members of the given group.

Sets the given property to value on all members of the given group, respecting the given GroupCallFlags.

  • void set_input_as_handled ( )

Marks the most recent input event as handled.

  • void set_quit_on_go_back ( bool enabled )

If true the application quits automatically on going back (e.g. on Android).

Configures screen stretching to the given StretchMode, StretchAspect, minimum size and shrink.