SceneTree
Manages the game loop via a hierarchy of nodes.
SceneTree.swift:28class SceneTree
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. an “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.
This object emits the following signals:
Superclasses
class MainLoop
Abstract base class for the game’s main loop.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
enum GroupCallFlags
class Signal1
Signal support.
class Signal2
Signal support.
class Signal3
Signal support.
class Signal4
Signal support.
Type members
static func createFrom(nativeHandle: UnsafeMutableRawPointer
) -> SceneTree Public because we want to allow the embed API to call this, but dont want to make it obvious in the constructors
class var godotClassName: StringName
Instance members
var autoAcceptQuit: Bool
If
true
, the application automatically accepts quitting requests.var currentScene: Node?
Returns the root node of the currently running scene, regardless of its structure.
var debugCollisionsHint: Bool
If
true
, collision shapes will be visible when running the game from the editor for debugging purposes.var debugPathsHint: Bool
If
true
, curves fromPath2D
andPath3D
nodes will be visible when running the game from the editor for debugging purposes.var editedSceneRoot: Node?
The root of the edited scene.
var multiplayerPoll: Bool
If
true
(default value), enables automatic polling of theMultiplayerAPI
for this SceneTree during [signal process_frame].var nodeAdded: Signal1
Emitted whenever a node is added to the
SceneTree
.var nodeConfigurationWarningChanged: Signal4
Emitted when a node’s configuration changed. Only emitted in
tool
mode.var nodeRemoved: Signal2
Emitted whenever a node is removed from the
SceneTree
.var nodeRenamed: Signal3
Emitted whenever a node is renamed.
var paused: Bool
If
true
, theSceneTree
is paused. Doing so will have the following behavior:var physicsFrame: SimpleSignal
Emitted immediately before
_physicsProcess(delta:)
is called on every node in theSceneTree
.var processFrame: SimpleSignal
Emitted immediately before
_process(delta:)
is called on every node in theSceneTree
.var quitOnGoBack: Bool
If
true
, the application quits automatically when navigating back (e.g. using the system “Back” button on Android).var root: Window?
The
SceneTree
’s rootWindow
.var treeChanged: SimpleSignal
Emitted whenever the
SceneTree
hierarchy changed (children being moved or renamed, etc.).var treeProcessModeChanged: SimpleSignal
This signal is only emitted in the editor, it allows the editor to update the visibility of disabled nodes. Emitted whenever any node’s
processMode
is changed.func callGroup(StringName, method: StringName, Variant...
) Calls
method
on each member of the given group. You can pass arguments tomethod
by specifying them at the end of the method call. If a node doesn’t have the given method or the argument list does not match (either in count or in types), it will be skipped.func callGroupFlags(Int64, group: StringName, method: StringName, Variant...
) Calls
method
on each member of the given group, respecting the givenGroupCallFlags
. You can pass arguments tomethod
by specifying them at the end of the method call. If a node doesn’t have the given method or the argument list does not match (either in count or in types), it will be skipped.func changeSceneToFile(path: String
) -> GodotError Changes the running scene to the one at the given
path
, after loading it into aPackedScene
and creating a new instance.func changeSceneToPacked(packedScene: PackedScene?
) -> GodotError Changes the running scene to a new instance of the given
PackedScene
(which must be valid).func createTimer(timeSec: Double, processAlways: Bool, processInPhysics: Bool, ignoreTimeScale: Bool
) -> SceneTreeTimer? Returns a
SceneTreeTimer
which will emit [signal SceneTreeTimer.timeout] after the given time in seconds elapsed in thisSceneTree
.func createTween(
) -> Tween? Creates and returns a new
Tween
. The Tween will start automatically on the next process frame or physics frame (depending onTween.TweenProcessMode
).func getFirstNodeInGroup(StringName
) -> Node? Returns the first node in the specified group, or
null
if the group is empty or does not exist.func getFrame(
) -> Int Returns the current frame number, i.e. the total frame count since the application started.
func getMultiplayer(forPath: NodePath
) -> MultiplayerAPI? Searches for the
MultiplayerAPI
configured for the given path, if one does not exist it searches the parent paths until one is found. If the path is empty, or none is found, the default one is returned. SeesetMultiplayer(_:rootPath:)
.func getNodeCount(
) -> Int32 Returns the number of nodes in this
SceneTree
.func getNodesInGroup(StringName
) -> ObjectCollection<Node> Returns a list of all nodes assigned to the given group.
func getProcessedTweens(
) -> ObjectCollection<Tween> Returns an array of currently existing
Tween
s in theSceneTree
(both running and paused).func hasGroup(name: StringName
) -> Bool Returns
true
if the given group exists.func notifyGroup(StringName, notification: Int32
) Sends the given notification to all members of the
group
.func notifyGroupFlags(callFlags: UInt32, group: StringName, notification: Int32
) Sends the given notification to all members of the
group
, respecting the givenGroupCallFlags
.func queueDelete(obj: Object?
) Queues the given object for deletion, delaying the call to
Object/free()
to the end of the current frame.func quit(exitCode: Int32
) Quits the application at the end of the current iteration. Argument
exitCode
can optionally be given (defaulting to 0) to customize the exit status code.func reloadCurrentScene(
) -> GodotError Reloads the currently active scene.
func setGroup(StringName, property: String, value: Variant
) Sets the given
property
tovalue
on all members of the given group.func setGroupFlags(callFlags: UInt32, group: StringName, property: String, value: Variant
) Sets the given
property
tovalue
on all members of the given group, respecting the givenGroupCallFlags
.func setMultiplayer(MultiplayerAPI?, rootPath: NodePath
) Sets a custom
MultiplayerAPI
with the givenrootPath
(controlling also the relative subpaths), or override the default one ifrootPath
is empty.func unloadCurrentScene(
) If a current scene is loaded, calling this method will unload it.