As one of the most important classes, the godot.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 godot.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.
godot.SceneTree
is the default godot.MainLoop
implementation used by scenes, and is thus in charge of the game loop.
Constructor
Variables
debugCollisionsHint:Bool
If true
, collision shapes will be visible when running the game from the editor for debugging purposes.
debugNavigationHint:Bool
If true
, navigation polygons will be visible when running the game from the editor for debugging purposes.
multiplayerPoll:Bool
If true
(default value), enables automatic polling of the godot.MultiplayerAPI
for this SceneTree during idle_frame
.
If false
, you need to manually call godot.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 godot.Mutex
protection when accessing the godot.MultiplayerAPI
from threads.
networkPeer:NetworkedMultiplayerPeer
The peer object to handle the RPC system (effectively enabling networking when set). Depending on the peer itself, the godot.SceneTree
will become a network server (check with godot.SceneTree.isNetworkServer
) and will set the root node's network mode to master, 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 godot.SceneTree
's signals.
read onlyonNodeConfigurationWarningChanged:Signal<(node:Node) ‑> Void>
node_configuration_warning_changed
signal.
paused:Bool
If true
, the godot.SceneTree
is paused. Doing so will have the following behavior:
-
2D and 3D physics will be stopped. This includes signals and collision detection.
-
godot.Node._Process
,godot.Node._PhysicsProcess
andgodot.Node._Input
will not be called anymore in nodes.
refuseNewNetworkConnections:Bool
If true
, the godot.SceneTree
's godot.SceneTree.networkPeer
refuses new incoming connections.
useFontOversampling:Bool
If true
, font oversampling is enabled. This means that godot.DynamicFont
s will be rendered at higher or lower size than configured based on the viewport's scaling ratio. For example, in a viewport scaled with a factor 1.5, a font configured with size 14 would be rendered with size 21 (14 * 1.5
).
Note: Font oversampling is only used if the viewport stretch mode is godot.SceneTree_StretchMode.viewport
, and if the stretch aspect mode is different from godot.SceneTree_StretchAspect.ignore
.
Note: This property is set automatically for the active godot.SceneTree
when the project starts based on the configuration of rendering/quality/dynamic_fonts/use_oversampling
in godot.ProjectSettings
. The property can however be overridden at runtime as needed.
Methods
callGroup(group:String, method:String, args:HaxeArray<Dynamic>):Dynamic
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. This method is equivalent of calling godot.SceneTree.callGroupFlags
with godot.SceneTree_GroupCallFlags.default
flag.
Note: method
may only have 5 arguments at most (7 arguments passed to this method in total).
Note: Due to design limitations, godot.SceneTree.callGroup
will fail silently if one of the arguments is null
.
Note: godot.SceneTree.callGroup
will always call methods with an one-frame delay, in a way similar to godot.Object.callDeferred
. To call methods immediately, use godot.SceneTree.callGroupFlags
with the godot.SceneTree_GroupCallFlags.realtime
flag.
callGroupFlags(flags:Int, group:String, method:String, args:HaxeArray<Dynamic>):Dynamic
Calls method
on each member of the given group, respecting the given godot.SceneTree_GroupCallFlags
. You can pass arguments to method
by specifying them at the end of the method call.
Note: method
may only have 5 arguments at most (8 arguments passed to this method in total).
Note: Due to design limitations, godot.SceneTree.callGroupFlags
will fail silently if one of the arguments is null
.
# Call the method immediately and in reverse order.
get_tree().call_group_flags(SceneTree.GROUP_CALL_REALTIME | SceneTree.GROUP_CALL_REVERSE, "bases", "destroy")
changeScene(path:String):Error
Changes the running scene to the one at the given path
, after loading it into a godot.PackedScene
and creating a new instance.
Returns OK
on success, ERR_CANT_OPEN
if the path
cannot be loaded into a godot.PackedScene
, or ERR_CANT_CREATE
if that scene cannot be instantiated.
Note: The scene change is deferred, which means that the new scene node is added on the next idle frame. You won't be able to access it immediately after the godot.SceneTree.changeScene
call.
changeSceneTo(packedScene:PackedScene):Error
Changes the running scene to a new instance of the given godot.PackedScene
.
Returns OK
on success or ERR_CANT_CREATE
if the scene cannot be instantiated.
Note: The scene change is deferred, which means that the new scene node is added on the next idle frame. You won't be able to access it immediately after the godot.SceneTree.changeSceneTo
call.
Note: Passing a value of null
into the method will unload the current scene without loading a new one.
createTimer(timeSec:Single, ?pauseModeProcess:Bool):SceneTreeTimer
Returns a godot.SceneTreeTimer
which will SceneTreeTimer.timeout
after the given time in seconds elapsed in this godot.SceneTree
. If pause_mode_process
is set to false
, pausing the godot.SceneTree
will also pause the timer.
Commonly used to create a one-shot delay timer as in the following example:
func some_function():
print("start")
yield(get_tree().create_timer(1.0), "timeout")
print("end")
The timer will be automatically freed after its time elapses.
getFrame():Int64
Returns the current frame number, i.e. the total frame count since the application started.
inlinegetNetworkConnectedPeers():Array<Int>
Returns the peer IDs of all connected peers of this godot.SceneTree
's godot.SceneTree.networkPeer
.
getNetworkUniqueId():Int
Returns the unique peer ID of this godot.SceneTree
's godot.SceneTree.networkPeer
.
isInputHandled():Bool
Returns true
if the most recent godot.InputEvent
was marked as handled with godot.SceneTree.setInputAsHandled
.
isNetworkServer():Bool
Returns true
if this godot.SceneTree
's godot.SceneTree.networkPeer
is in server mode (listening for connections).
notifyGroup(group:String, notification:Int):Void
Sends the given notification to all members of the group
.
notifyGroupFlags(callFlags:UInt, group:String, notification:Int):Void
Sends the given notification to all members of the group
, respecting the given godot.SceneTree_GroupCallFlags
.
queueDelete(obj:Object):Void
Queues the given object for deletion, delaying the call to godot.Object.free
to after the current frame.
quit(?exitCode:Int):Void
Quits the application at the end of the current iteration. A process exit_code
can optionally be passed as an argument. If this argument is 0
or greater, it will override the godot.OS.exitCode
defined before quitting the application.
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.
reloadCurrentScene():Error
Reloads the currently active scene.
Returns OK
on success, ERR_UNCONFIGURED
if no godot.SceneTree.currentScene
was defined yet, ERR_CANT_OPEN
if godot.SceneTree.currentScene
cannot be loaded into a godot.PackedScene
, or ERR_CANT_CREATE
if the scene cannot be instantiated.
setAutoAcceptQuit(enabled:Bool):Void
If true
, the application automatically accepts quitting. Enabled by default.
For mobile platforms, see godot.SceneTree.setQuitOnGoBack
.
setGroup(group:String, property:String, value:Dynamic):Void
Sets the given property
to value
on all members of the given group.
setGroupFlags(callFlags:UInt, group:String, property:String, value:Dynamic):Void
Sets the given property
to value
on all members of the given group, respecting the given godot.SceneTree_GroupCallFlags
.
setQuitOnGoBack(enabled:Bool):Void
If true
, the application quits automatically on going back (e.g. on Android). Enabled by default.
To handle 'Go Back' button when this option is disabled, use godot.MainLoop.notificationWmGoBackRequest
.
setScreenStretch(mode:SceneTree_StretchMode, aspect:SceneTree_StretchAspect, minsize:Vector2, ?scale:Single):Void
Configures screen stretching to the given godot.SceneTree_StretchMode
, godot.SceneTree_StretchAspect
, minimum size and scale
.