Manages the game loop via a hierarchy of nodes.
    public class SceneTree : MainLoop

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.

SceneTree is the default MainLoop implementation used by scenes, and is thus in charge of the game loop.

Inheritance Chain

Constructors

    public SceneTree()

Signals

    "connected_to_server" ()

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

    "connection_failed" ()

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

    "files_dropped" (PoolStringArray files, int screen)

Emitted when files are dragged from the OS file manager and dropped in the game window. The arguments are a list of file paths and the identifier of the screen where the drag originated.

    "global_menu_action" (Nil id, Nil meta)

Emitted whenever global menu item is clicked.

    "idle_frame" ()

Emitted immediately before Node._Process(float) is called on every node in the SceneTree.

    "network_peer_connected" (int id)

Emitted whenever this SceneTree’s NetworkPeer 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 NetworkPeer disconnects from a peer. Clients get notified when other clients disconnect from the same server.

    "node_added" (Node node)

Emitted whenever a node is added to the SceneTree.

    "node_configuration_warning_changed" (Node node)

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

    "node_removed" (Node node)

Emitted whenever a node is removed from the SceneTree.

    "node_renamed" (Node node)

Emitted whenever a node is renamed.

    "physics_frame" ()

Emitted immediately before Node._PhysicsProcess(float) is called on every node in the SceneTree.

    "screen_resized" ()

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

    "server_disconnected" ()

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

    "tree_changed" ()

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

Properties

    public Node CurrentScene { get; set; }

The current scene.

    public bool DebugCollisionsHint { get; set; }

If true, collision shapes will be visible when running the game from the editor for debugging purposes.

    public bool DebugNavigationHint { get; set; }

If true, navigation polygons will be visible when running the game from the editor for debugging purposes.

    public Node EditedSceneRoot { get; set; }

The root of the edited scene.

    public MultiplayerAPI Multiplayer { get; set; }

The default MultiplayerAPI instance for this SceneTree.

    public bool MultiplayerPoll { get; set; }

If true (default value), enables automatic polling of the MultiplayerAPI for this SceneTree during idle_frame.

If false, you need to manually call MultiplayerAPI.Poll() to process network packets and deliver RPCs/RSETs. This allows running RPCs/RSETs in a different loop (e.g. physics, thread, specific time step) and for manual Mutex protection when accessing the MultiplayerAPI from threads.

    public NetworkedMultiplayerPeer NetworkPeer { get; set; }

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 IsNetworkServer()) and will set the root node’s network mode to master (see NETWORK_MODE_* constants in Node), or it will become a regular peer with the root node set to puppet. 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.

    public bool Paused { get; set; }

If true, the SceneTree is paused. Doing so will have the following behavior:

    public bool RefuseNewNetworkConnections { get; set; }

If true, the SceneTree’s NetworkPeer refuses new incoming connections.

    public Viewport Root { get; }

The SceneTree’s root Viewport.

    public bool UseFontOversampling { get; set; }

If true, font oversampling is used.

Methods

    public object CallGroup(string group, string method, params object[] args)

    public object CallGroupFlags(int flags, string group, string method, params object[] args)

    public Error ChangeScene(string path)

Changes the running scene to the one at the given path, after loading it into a PackedScene and creating a new instance.

Returns [constant OK] on success, [constant ERR_CANT_OPEN] if the path cannot be loaded into a PackedScene, or [constant ERR_CANT_CREATE] if that scene cannot be instantiated.

    public Error ChangeSceneTo(PackedScene packedScene)

Changes the running scene to a new instance of the given PackedScene.

Returns [constant OK] on success or [constant ERR_CANT_CREATE] if the scene cannot be instantiated.

    public SceneTreeTimer CreateTimer(float timeSec, bool pauseModeProcess = true)

Returns a SceneTreeTimer which will timeout after the given time in seconds elapsed in this SceneTree. If pauseModeProcess is set to false, pausing the SceneTree will also pause the timer.

Commonly used to create a one-shot delay timer as in the following example:

[codeblock]

func some_function():

print(“start”)

yield(get_tree().create_timer(1.0), “timeout”)

print(“end”)

[/codeblock]

    [Obsolete("GetCurrentScene is deprecated. Use the CurrentScene property instead.")]
    public Node GetCurrentScene()

Getter for CurrentScene

    [Obsolete("GetEditedSceneRoot is deprecated. Use the EditedSceneRoot property instead.")]
    public Node GetEditedSceneRoot()

Getter for EditedSceneRoot

    public long GetFrame()

    [Obsolete("GetMultiplayer is deprecated. Use the Multiplayer property instead.")]
    public MultiplayerAPI GetMultiplayer()

Getter for Multiplayer

    public int[] GetNetworkConnectedPeers()

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

    [Obsolete("GetNetworkPeer is deprecated. Use the NetworkPeer property instead.")]
    public NetworkedMultiplayerPeer GetNetworkPeer()

Getter for NetworkPeer

    public int GetNetworkUniqueId()

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

    public int GetNodeCount()

Returns the number of nodes in this SceneTree.

    public Godot.Collections.Array GetNodesInGroup(string group)

Returns a list of all nodes assigned to the given group.

    [Obsolete("GetRoot is deprecated. Use the Root property instead.")]
    public Viewport GetRoot()

Getter for Root

    public int GetRpcSenderId()

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

    public bool HasGroup(string name)

Returns true if the given group exists.

    public bool HasNetworkPeer()

Returns true if there is a NetworkPeer set.

    [Obsolete("IsDebuggingCollisionsHint is deprecated. Use the DebugCollisionsHint property instead.")]
    public bool IsDebuggingCollisionsHint()

Getter for DebugCollisionsHint

    [Obsolete("IsDebuggingNavigationHint is deprecated. Use the DebugNavigationHint property instead.")]
    public bool IsDebuggingNavigationHint()

Getter for DebugNavigationHint

    public bool IsInputHandled()

Returns true if the most recent InputEvent was marked as handled with SetInputAsHandled().

    [Obsolete("IsMultiplayerPollEnabled is deprecated. Use the MultiplayerPoll property instead.")]
    public bool IsMultiplayerPollEnabled()

Getter for MultiplayerPoll

    public bool IsNetworkServer()

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

    [Obsolete("IsPaused is deprecated. Use the Paused property instead.")]
    public bool IsPaused()

Getter for Paused

    [Obsolete("IsRefusingNewNetworkConnections is deprecated. Use the RefuseNewNetworkConnections property instead.")]
    public bool IsRefusingNewNetworkConnections()

Getter for RefuseNewNetworkConnections

    [Obsolete("IsUsingFontOversampling is deprecated. Use the UseFontOversampling property instead.")]
    public bool IsUsingFontOversampling()

Getter for UseFontOversampling

    public void NotifyGroup(string group, int notification)

Sends the given notification to all members of the group.

    public void NotifyGroupFlags(uint callFlags, string group, int notification)

    public void QueueDelete(Object obj)

Queues the given object for deletion, delaying the call to Object.Free() to after the current frame.

    public void Quit()

Quits the application.

    public Error ReloadCurrentScene()

Reloads the currently active scene.

Returns an [enum Error] code as described in ChangeScene(string), with the addition of [constant ERR_UNCONFIGURED] if no CurrentScene was defined yet.

    public void SetAutoAcceptQuit(bool enabled)

If true, the application automatically accepts quitting. Enabled by default.

    [Obsolete("SetCurrentScene is deprecated. Use the CurrentScene property instead.")]
    public void SetCurrentScene(Node childNode)

Setter for CurrentScene

    [Obsolete("SetDebugCollisionsHint is deprecated. Use the DebugCollisionsHint property instead.")]
    public void SetDebugCollisionsHint(bool enable)

Setter for DebugCollisionsHint

    [Obsolete("SetDebugNavigationHint is deprecated. Use the DebugNavigationHint property instead.")]
    public void SetDebugNavigationHint(bool enable)

Setter for DebugNavigationHint

    [Obsolete("SetEditedSceneRoot is deprecated. Use the EditedSceneRoot property instead.")]
    public void SetEditedSceneRoot(Node scene)

Setter for EditedSceneRoot

    public void SetGroup(string group, string property, object value)

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

    public void SetGroupFlags(uint callFlags, string group, string property, object value)

    public void SetInputAsHandled()

Marks the most recent InputEvent as handled.

    [Obsolete("SetMultiplayer is deprecated. Use the Multiplayer property instead.")]
    public void SetMultiplayer(MultiplayerAPI multiplayer)

Setter for Multiplayer

    [Obsolete("SetMultiplayerPollEnabled is deprecated. Use the MultiplayerPoll property instead.")]
    public void SetMultiplayerPollEnabled(bool enabled)

Setter for MultiplayerPoll

    [Obsolete("SetNetworkPeer is deprecated. Use the NetworkPeer property instead.")]
    public void SetNetworkPeer(NetworkedMultiplayerPeer peer)

Setter for NetworkPeer

    [Obsolete("SetPause is deprecated. Use the Paused property instead.")]
    public void SetPause(bool enable)

Setter for Paused

    public void SetQuitOnGoBack(bool enabled)

If true, the application quits automatically on going back (e.g. on Android). Enabled by default.

    [Obsolete("SetRefuseNewNetworkConnections is deprecated. Use the RefuseNewNetworkConnections property instead.")]
    public void SetRefuseNewNetworkConnections(bool refuse)

Setter for RefuseNewNetworkConnections

    public void SetScreenStretch(StretchMode mode, StretchAspect aspect, Vector2 minsize, float shrink = 1f)

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

    [Obsolete("SetUseFontOversampling is deprecated. Use the UseFontOversampling property instead.")]
    public void SetUseFontOversampling(bool enable)

Setter for UseFontOversampling

Inner Types

GroupCallFlags

Name Value Description
Default 0 Call a group with no flags (default).
Reverse 1 Call a group in reverse scene order.
Realtime 2 Call a group immediately (calls are normally made on idle).
Unique 4 Call a group only once even if the call is executed many times.

StretchAspect

Name Value Description
Ignore 0 Fill the window with the content stretched to cover excessive space. Content may appear stretched.
Keep 1 Retain the same aspect ratio by padding with black bars on either axis. This prevents distortion.
KeepWidth 2 Expand vertically. Left/right black bars may appear if the window is too wide.
KeepHeight 3 Expand horizontally. Top/bottom black bars may appear if the window is too tall.
Expand 4 Expand in both directions, retaining the same aspect ratio. This prevents distortion while avoiding black bars.

StretchMode

Name Value Description
Disabled 0 No stretching.
Mode2d    
Viewport 2 Keep the specified display resolution. No interpolation. Content may appear pixelated.
Tags: