SceneTree manages 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.

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 whenever files are drag-and-dropped onto the window.

    "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.

    "physics_frame" ()

Emitted immediately before Node._PhysicsProcess(float) 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 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; }

    public bool DebugNavigationHint { get; set; }

    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) 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 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 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 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:

  • 2D and 3D physics will be stopped.

  • _process and _physics_process will not be called anymore in nodes.

  • _input and _input_event will not be called anymore either.

    public bool RefuseNewNetworkConnections { get; set; }

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

    public Viewport Root { get; }

The SceneTree’s 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 to the scene at the given path.

    public Error ChangeSceneTo(PackedScene packedScene)

Changes to the given PackedScene.

    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]

    public Node GetCurrentScene()

Getter for CurrentScene

    public Node GetEditedSceneRoot()

Getter for EditedSceneRoot

    public int GetFrame()

Returns the current frame, i.e. number of frames since the application started.

    public MultiplayerAPI GetMultiplayer()

Getter for Multiplayer

    public int[] GetNetworkConnectedPeers()

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

    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 all nodes assigned to the given group.

    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.

    public bool IsDebuggingCollisionsHint()

Getter for DebugCollisionsHint

    public bool IsDebuggingNavigationHint()

Getter for DebugNavigationHint

    public bool IsInputHandled()

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

    public bool IsMultiplayerPollEnabled()

Getter for MultiplayerPoll

    public bool IsNetworkServer()

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

    public bool IsPaused()

Getter for Paused

    public bool IsRefusingNewNetworkConnections()

Getter for RefuseNewNetworkConnections

    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(int callFlags, string group, int notification)

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

    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.

    public void SetAutoAcceptQuit(bool enabled)

If true, the application automatically accepts quitting.

    public void SetCurrentScene(Node childNode)

Setter for CurrentScene

    public void SetDebugCollisionsHint(bool enable)

Setter for DebugCollisionsHint

    public void SetDebugNavigationHint(bool enable)

Setter for DebugNavigationHint

    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(int callFlags, string group, string property, object value)

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

    public void SetInputAsHandled()

Marks the most recent input event as handled.

    public void SetMultiplayer(MultiplayerAPI multiplayer)

Setter for Multiplayer

    public void SetMultiplayerPollEnabled(bool enabled)

Setter for MultiplayerPoll

    public void SetNetworkPeer(NetworkedMultiplayerPeer peer)

Setter for NetworkPeer

    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).

    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.

    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 elongated.
Keep 1 Retain the same aspect ratio by padding with black bars in either axes. No expansion of content.
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. No 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: