Documentation
¶
Overview ¶
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, fetched 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 added to 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 nodes belonging to any given group.
SceneTree is the default MainLoop implementation used by the engine, and is thus in charge of the game loop.
Index ¶
- func Add(node Node.Any)
- func AddNamed(name string, node Node.Any)
- type Advanced
- type Any
- type Expanded
- type Extension
- type GroupCallFlags
- type ID
- type Instance
- func (self Instance) AsMainLoop() MainLoop.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsSceneTree() Instance
- func (self Instance) AutoAcceptQuit() bool
- func (self Instance) CallGroup(group string, method string, args ...any)
- func (self Instance) CallGroupFlags(flags GroupCallFlags, group string, method string, args ...any)
- func (self Instance) ChangeSceneToFile(path string) error
- func (self Instance) ChangeSceneToPacked(packed_scene PackedScene.Instance) error
- func (self Instance) CreateTimer(time_sec Float.X) SceneTreeTimer.Instance
- func (self Instance) CreateTween() Tween.Instance
- func (self Instance) CurrentScene() Node.Instance
- func (self Instance) DebugCollisionsHint() bool
- func (self Instance) DebugNavigationHint() bool
- func (self Instance) DebugPathsHint() bool
- func (self Instance) EditedSceneRoot() Node.Instance
- func (self Instance) GetFirstNodeInGroup(group string) Node.Instance
- func (self Instance) GetFrame() int
- func (self Instance) GetMultiplayer() MultiplayerAPI.Instance
- func (self Instance) GetNodeCount() int
- func (self Instance) GetNodeCountInGroup(group string) int
- func (self Instance) GetNodesInGroup(group string) []Node.Instance
- func (self Instance) GetProcessedTweens() []Tween.Instance
- func (self Instance) HasGroup(name string) bool
- func (self Instance) ID() ID
- func (self Instance) IsAccessibilityEnabled() bool
- func (self Instance) IsAccessibilitySupported() bool
- func (self Instance) MoreArgs() MoreArgs
- func (self Instance) MultiplayerPoll() bool
- func (self Instance) NotifyGroup(group string, notification int)
- func (self Instance) NotifyGroupFlags(call_flags int, group string, notification int)
- func (self Instance) OnNodeAdded(cb func(node Node.Instance), flags ...Signal.Flags)
- func (self Instance) OnNodeConfigurationWarningChanged(cb func(node Node.Instance), flags ...Signal.Flags)
- func (self Instance) OnNodeRemoved(cb func(node Node.Instance), flags ...Signal.Flags)
- func (self Instance) OnNodeRenamed(cb func(node Node.Instance), flags ...Signal.Flags)
- func (self Instance) OnPhysicsFrame(cb func(), flags ...Signal.Flags)
- func (self Instance) OnProcessFrame(cb func(), flags ...Signal.Flags)
- func (self Instance) OnSceneChanged(cb func(), flags ...Signal.Flags)
- func (self Instance) OnTreeChanged(cb func(), flags ...Signal.Flags)
- func (self Instance) OnTreeProcessModeChanged(cb func(), flags ...Signal.Flags)
- func (self Instance) Paused() bool
- func (self Instance) PhysicsInterpolation() bool
- func (self Instance) QueueDelete(obj Object.Instance)
- func (self Instance) Quit()
- func (self Instance) QuitOnGoBack() bool
- func (self Instance) ReloadCurrentScene() error
- func (self Instance) Root() Window.Instance
- func (self Instance) SetAutoAcceptQuit(value bool)
- func (self Instance) SetCurrentScene(value Node.Instance)
- func (self Instance) SetDebugCollisionsHint(value bool)
- func (self Instance) SetDebugNavigationHint(value bool)
- func (self Instance) SetDebugPathsHint(value bool)
- func (self Instance) SetEditedSceneRoot(value Node.Instance)
- func (self Instance) SetGroup(group string, property string, value any)
- func (self Instance) SetGroupFlags(call_flags int, group string, property string, value any)
- func (self Instance) SetMultiplayer(multiplayer MultiplayerAPI.Instance)
- func (self Instance) SetMultiplayerPoll(value bool)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetPaused(value bool)
- func (self Instance) SetPhysicsInterpolation(value bool)
- func (self Instance) SetQuitOnGoBack(value bool)
- func (self Instance) UnloadCurrentScene()
- func (self Instance) Virtual(name string) reflect.Value
- type MoreArgs
- func (self MoreArgs) CreateTimer(time_sec Float.X, process_always bool, process_in_physics bool, ...) SceneTreeTimer.Instance
- func (self MoreArgs) GetMultiplayer(for_path string) MultiplayerAPI.Instance
- func (self MoreArgs) Quit(exit_code int)
- func (self MoreArgs) SetMultiplayer(multiplayer MultiplayerAPI.Instance, root_path string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsMainLoop ¶
func (*Extension[T]) AsSceneTree ¶
type GroupCallFlags ¶
type GroupCallFlags int //gd:SceneTree.GroupCallFlags
const ( // Call nodes within a group with no special behavior (default). GroupCallDefault GroupCallFlags = 0 // Call nodes within a group in reverse tree hierarchy order (all nested children are called before their respective parent nodes). GroupCallReverse GroupCallFlags = 1 // Call nodes within a group at the end of the current frame (can be either process or physics frame), similar to [Object.CallDeferred]. // // [Object.CallDeferred]: https://pkg.go.dev/graphics.gd/variant/Object#CallDeferred GroupCallDeferred GroupCallFlags = 2 // Call nodes within a group only once, even if the call is executed many times in the same frame. Must be combined with [GroupCallDeferred] to work. // // Note: Different arguments are not taken into account. Therefore, when the same call is executed with different arguments, only the first call will be performed. GroupCallUnique GroupCallFlags = 4 )
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func Get ¶
Returns the [SceneTree] that contains this node. If this node is not inside the tree, generates an error and returns [code]null[/code]. See also [method is_inside_tree].
func (Instance) AsMainLoop ¶
func (Instance) AsSceneTree ¶
func (Instance) AutoAcceptQuit ¶
If true, the application automatically accepts quitting requests.
For mobile platforms, see QuitOnGoBack.
func (Instance) CallGroup ¶
Calls 'method' on each node inside this tree added to the given 'group'. You can pass arguments to 'method' by specifying them at the end of this method call. Nodes that cannot call 'method' (either because the method doesn't exist or the arguments do not match) are ignored. See also SetGroup and NotifyGroup.
Note: This method acts immediately on all selected nodes at once, which may cause stuttering in some performance-intensive situations.
Note: In C#, 'method' must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new string on each call.
func (Instance) CallGroupFlags ¶
func (self Instance) CallGroupFlags(flags GroupCallFlags, group string, method string, args ...any)
Calls the given 'method' on each node inside this tree added to the given 'group'. Use 'flags' to customize this method's behavior (see GroupCallFlags). Additional arguments for 'method' can be passed at the end of this method. Nodes that cannot call 'method' (either because the method doesn't exist or the arguments do not match) are ignored.
// Calls "hide" to all nodes of the "enemies" group, at the end of the frame and in reverse tree order. SceneTree.Get(node).CallGroupFlags( SceneTree.GroupCallDeferred|SceneTree.GroupCallReverse, "enemies", "hide")
Note: In C#, 'method' must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new string on each call.
func (Instance) ChangeSceneToFile ¶
Changes the running scene to the one at the given 'path', after loading it into a PackedScene and creating a new instance.
Returns [Ok] on success, [ErrCantOpen] if the 'path' cannot be loaded into a PackedScene, or [ErrCantCreate] if that scene cannot be instantiated.
Note: See ChangeSceneToPacked for details on the order of operations.
func (Instance) ChangeSceneToPacked ¶
func (self Instance) ChangeSceneToPacked(packed_scene PackedScene.Instance) error
Changes the running scene to a new instance of the given PackedScene (which must be valid).
Returns [Ok] on success, [ErrCantCreate] if the scene cannot be instantiated, or [ErrInvalidParameter] if the scene is invalid.
Note: Operations happen in the following order when ChangeSceneToPacked is called:
1. The current scene node is immediately removed from the tree. From that point, Node.GetTree called on the current (outgoing) scene will return null. CurrentScene will be null, too, because the new scene is not available yet.
2. At the end of the frame, the formerly current scene, already removed from the tree, will be deleted (freed from memory) and then the new scene will be instantiated and added to the tree. Node.GetTree and CurrentScene will be back to working as usual.
This ensures that both scenes aren't running at the same time, while still freeing the previous scene in a safe way similar to Node.QueueFree.
If you want to reliably access the new scene, await the OnSceneChanged signal.
func (Instance) CreateTimer ¶
func (self Instance) CreateTimer(time_sec Float.X) SceneTreeTimer.Instance
Returns a new SceneTreeTimer. After 'time_sec' in seconds have passed, the timer will emit OnScenetreetimer.Timeout and will be automatically freed.
If 'process_always' is false, the timer will be paused when setting SceneTree.Paused to true.
If 'process_in_physics' is true, the timer will update at the end of the physics frame, instead of the process frame.
If 'ignore_time_scale' is true, the timer will ignore Engine.TimeScale and update with the real, elapsed time.
This method is commonly used to create a one-shot delay timer, as in the following example:
fmt.Println("start") SceneTree.Get(node).CreateTimer(1.0).OnTimeout(func() { fmt.Println("end") }, Signal.OneShot)
Note: The timer is always updated after all of the nodes in the tree. A node's Node.Process method would be called before the timer updates (or Node.PhysicsProcess if 'process_in_physics' is set to true).
func (Instance) CreateTween ¶
Creates and returns a new Tween processed in this tree. The Tween will start automatically on the next process frame or physics frame (depending on its [Tween.TweenProcessMode]).
Note: A Tween created using this method is not bound to any Node. It may keep working until there is nothing left to animate. If you want the Tween to be automatically killed when the Node is freed, use Node.CreateTween or Tween.BindNode.
func (Instance) CurrentScene ¶
The root node of the currently loaded main scene, usually as a direct child of Root. See also ChangeSceneToFile, ChangeSceneToPacked, and ReloadCurrentScene.
Warning: Setting this property directly may not work as expected, as it does not add or remove any nodes from this tree.
func (Instance) DebugCollisionsHint ¶
If true, collision shapes will be visible when running the game from the editor for debugging purposes.
Note: This property is not designed to be changed at run-time. Changing the value of DebugCollisionsHint while the project is running will not have the desired effect.
func (Instance) DebugNavigationHint ¶
If true, navigation polygons will be visible when running the game from the editor for debugging purposes.
Note: This property is not designed to be changed at run-time. Changing the value of DebugNavigationHint while the project is running will not have the desired effect.
func (Instance) DebugPathsHint ¶
If true, curves from Path2D and Path3D nodes will be visible when running the game from the editor for debugging purposes.
Note: This property is not designed to be changed at run-time. Changing the value of DebugPathsHint while the project is running will not have the desired effect.
func (Instance) EditedSceneRoot ¶
The root of the scene currently being edited in the editor. This is usually a direct child of Root.
Note: This property does nothing in release builds.
func (Instance) GetFirstNodeInGroup ¶
Returns the first Node found inside the tree, that has been added to the given 'group', in scene hierarchy order. Returns null if no match is found. See also GetNodesInGroup.
func (Instance) GetFrame ¶
Returns how many physics process steps have been processed, since the application started. This is not a measurement of elapsed time. See also OnPhysicsFrame. For the number of frames rendered, see Engine.GetProcessFrames.
func (Instance) GetMultiplayer ¶
func (self Instance) GetMultiplayer() MultiplayerAPI.Instance
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. See SetMultiplayer.
func (Instance) GetNodeCount ¶
Returns the number of nodes inside this tree.
func (Instance) GetNodeCountInGroup ¶
Returns the number of nodes assigned to the given group.
func (Instance) GetNodesInGroup ¶
Returns an slice containing all nodes inside this tree, that have been added to the given 'group', in scene hierarchy order.
func (Instance) GetProcessedTweens ¶
Returns an slice of currently existing Tweens in the tree, including paused tweens.
func (Instance) HasGroup ¶
Returns true if a node added to the given group 'name' exists in the tree.
func (Instance) IsAccessibilityEnabled ¶
Returns true if accessibility features are enabled, and accessibility information updates are actively processed.
func (Instance) IsAccessibilitySupported ¶
Returns true if accessibility features are supported by the OS and enabled in project settings.
func (Instance) MoreArgs ¶
MoreArgs enables certain functions to be called with additional 'optional' arguments.
func (Instance) MultiplayerPoll ¶
If true (default value), enables automatic polling of the MultiplayerAPI for this SceneTree during OnProcessFrame.
If false, you need to manually call MultiplayerAPI.Poll to process network packets and deliver RPCs. This allows running RPCs in a different loop (e.g. physics, thread, specific time step) and for manual Mutex protection when accessing the MultiplayerAPI from threads.
func (Instance) NotifyGroup ¶
Calls Object.Notification with the given 'notification' to all nodes inside this tree added to the 'group'. See also Godot notifications and CallGroup and SetGroup.
Note: This method acts immediately on all selected nodes at once, which may cause stuttering in some performance-intensive situations.
func (Instance) NotifyGroupFlags ¶
Calls Object.Notification with the given 'notification' to all nodes inside this tree added to the 'group'. Use 'call_flags' to customize this method's behavior (see GroupCallFlags).
func (Instance) OnNodeAdded ¶
Emitted when the 'node' enters this tree.
func (Instance) OnNodeConfigurationWarningChanged ¶
func (self Instance) OnNodeConfigurationWarningChanged(cb func(node Node.Instance), flags ...Signal.Flags)
Emitted when the 'node”s Node.UpdateConfigurationWarnings is called. Only emitted in the editor.
func (Instance) OnNodeRemoved ¶
Emitted when the 'node' exits this tree.
func (Instance) OnNodeRenamed ¶
Emitted when the 'node”s Node.Name is changed.
func (Instance) OnPhysicsFrame ¶
Emitted immediately before Node.PhysicsProcess is called on every node in this tree.
func (Instance) OnProcessFrame ¶
Emitted immediately before Node.Process is called on every node in this tree.
func (Instance) OnSceneChanged ¶
Emitted after the new scene is added to scene tree and initialized. Can be used to reliably access CurrentScene when changing scenes.
func (Instance) OnTreeChanged ¶
Emitted any time the tree's hierarchy changes (nodes being moved, renamed, etc.).
func (Instance) OnTreeProcessModeChanged ¶
Emitted when the Node.ProcessMode of any node inside the tree is changed. Only emitted in the editor, to update the visibility of disabled nodes.
func (Instance) Paused ¶
If true, the scene tree is considered paused. This causes the following behavior:
- 2D and 3D physics will be stopped, as well as collision detection and related signals.
- Depending on each node's Node.ProcessMode, their Node.Process, Node.PhysicsProcess and Node.Input callback methods may not called anymore.
func (Instance) PhysicsInterpolation ¶
If true, the renderer will interpolate the transforms of objects (both physics and non-physics) between the last two transforms, so that smooth motion is seen even when physics ticks do not coincide with rendered frames.
The default value of this property is controlled by ProjectSettings "physics/common/physics_interpolation".
Note: Although this is a global setting, finer control of individual branches of the SceneTree is possible using Node.PhysicsInterpolationMode.
func (Instance) QueueDelete ¶
Queues the given 'obj' to be deleted, calling its Object.Free at the end of the current frame. This method is similar to Node.QueueFree.
func (Instance) Quit ¶
func (self Instance) Quit()
Quits the application at the end of the current iteration, with the given 'exit_code'.
By convention, an exit code of 0 indicates success, whereas any other exit code indicates an error. For portability reasons, it should be between 0 and 125 (inclusive).
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.
func (Instance) QuitOnGoBack ¶
If true, the application quits automatically when navigating back (e.g. using the system "Back" button on Android).
To handle 'Go Back' button when this option is disabled, use [Displayserver.WindowEventGoBackRequest].
func (Instance) ReloadCurrentScene ¶
Reloads the currently active scene, replacing CurrentScene with a new instance of its original PackedScene.
Returns [Ok] on success, [ErrUnconfigured] if no CurrentScene is defined, [ErrCantOpen] if CurrentScene cannot be loaded into a PackedScene, or [ErrCantCreate] if the scene cannot be instantiated.
func (Instance) Root ¶
The tree's root Window. This is top-most Node of the scene tree, and is always present. An absolute node path always starts from this node. Children of the root node may include the loaded CurrentScene, as well as any AutoLoad configured in the Project Settings.
Warning: Do not delete this node. This will result in unstable behavior, followed by a crash.
func (Instance) SetAutoAcceptQuit ¶
SetAutoAcceptQuit sets the property returned by [IsAutoAcceptQuit].
func (Instance) SetCurrentScene ¶
SetCurrentScene sets the property returned by [GetCurrentScene].
func (Instance) SetDebugCollisionsHint ¶
SetDebugCollisionsHint sets the property returned by [IsDebuggingCollisionsHint].
func (Instance) SetDebugNavigationHint ¶
SetDebugNavigationHint sets the property returned by [IsDebuggingNavigationHint].
func (Instance) SetDebugPathsHint ¶
SetDebugPathsHint sets the property returned by [IsDebuggingPathsHint].
func (Instance) SetEditedSceneRoot ¶
SetEditedSceneRoot sets the property returned by [GetEditedSceneRoot].
func (Instance) SetGroup ¶
Sets the given 'property' to 'value' on all nodes inside this tree added to the given 'group'. Nodes that do not have the 'property' are ignored. See also CallGroup and NotifyGroup.
Note: This method acts immediately on all selected nodes at once, which may cause stuttering in some performance-intensive situations.
Note: In C#, 'property' must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new string on each call.
func (Instance) SetGroupFlags ¶
Sets the given 'property' to 'value' on all nodes inside this tree added to the given 'group'. Nodes that do not have the 'property' are ignored. Use 'call_flags' to customize this method's behavior (see GroupCallFlags).
Note: In C#, 'property' must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new string on each call.
func (Instance) SetMultiplayer ¶
func (self Instance) SetMultiplayer(multiplayer MultiplayerAPI.Instance)
Sets a custom MultiplayerAPI with the given 'root_path' (controlling also the relative subpaths), or override the default one if 'root_path' is empty.
Note: No MultiplayerAPI must be configured for the subpath containing 'root_path', nested custom multiplayers are not allowed. I.e. if one is configured for "/root/Foo" setting one for "/root/Foo/Bar" will cause an error.
Note: SetMultiplayer should be called before the child nodes are ready at the given 'root_path'. If multiplayer nodes like MultiplayerSpawner or MultiplayerSynchronizer are added to the tree before the custom multiplayer API is set, they will not work.
func (Instance) SetMultiplayerPoll ¶
SetMultiplayerPoll sets the property returned by [IsMultiplayerPollEnabled].
func (Instance) SetPhysicsInterpolation ¶
SetPhysicsInterpolation sets the property returned by [IsPhysicsInterpolationEnabled].
func (Instance) SetQuitOnGoBack ¶
SetQuitOnGoBack sets the property returned by [IsQuitOnGoBack].
func (Instance) UnloadCurrentScene ¶
func (self Instance) UnloadCurrentScene()
If a current scene is loaded, calling this method will unload it.
type MoreArgs ¶
MoreArgs is a container for Instance functions with additional 'optional' arguments.
func (MoreArgs) CreateTimer ¶
func (self MoreArgs) CreateTimer(time_sec Float.X, process_always bool, process_in_physics bool, ignore_time_scale bool) SceneTreeTimer.Instance
Returns a new SceneTreeTimer. After 'time_sec' in seconds have passed, the timer will emit OnScenetreetimer.Timeout and will be automatically freed.
If 'process_always' is false, the timer will be paused when setting SceneTree.Paused to true.
If 'process_in_physics' is true, the timer will update at the end of the physics frame, instead of the process frame.
If 'ignore_time_scale' is true, the timer will ignore Engine.TimeScale and update with the real, elapsed time.
This method is commonly used to create a one-shot delay timer, as in the following example:
fmt.Println("start") SceneTree.Get(node).CreateTimer(1.0).OnTimeout(func() { fmt.Println("end") }, Signal.OneShot)
Note: The timer is always updated after all of the nodes in the tree. A node's Node.Process method would be called before the timer updates (or Node.PhysicsProcess if 'process_in_physics' is set to true).
func (MoreArgs) GetMultiplayer ¶
func (self MoreArgs) GetMultiplayer(for_path string) MultiplayerAPI.Instance
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. See SetMultiplayer.
func (MoreArgs) Quit ¶
Quits the application at the end of the current iteration, with the given 'exit_code'.
By convention, an exit code of 0 indicates success, whereas any other exit code indicates an error. For portability reasons, it should be between 0 and 125 (inclusive).
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.
func (MoreArgs) SetMultiplayer ¶
func (self MoreArgs) SetMultiplayer(multiplayer MultiplayerAPI.Instance, root_path string)
Sets a custom MultiplayerAPI with the given 'root_path' (controlling also the relative subpaths), or override the default one if 'root_path' is empty.
Note: No MultiplayerAPI must be configured for the subpath containing 'root_path', nested custom multiplayers are not allowed. I.e. if one is configured for "/root/Foo" setting one for "/root/Foo/Bar" will cause an error.
Note: SetMultiplayer should be called before the child nodes are ready at the given 'root_path'. If multiplayer nodes like MultiplayerSpawner or MultiplayerSynchronizer are added to the tree before the custom multiplayer API is set, they will not work.