Documentation
¶
Overview ¶
As one of the most important classes, the graphics.gd/classdb/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 graphics.gd/classdb/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.
graphics.gd/classdb/SceneTree is the default graphics.gd/classdb/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
- func (self Expanded) CreateTimer(time_sec Float.X, process_always bool, process_in_physics bool, ...) SceneTreeTimer.Instance
- func (self Expanded) GetMultiplayer(for_path string) MultiplayerAPI.Instance
- func (self Expanded) Quit(exit_code int)
- func (self Expanded) SetMultiplayer(multiplayer MultiplayerAPI.Instance, root_path string)
- 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 int, 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) 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
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 Expanded ¶
func (Expanded) CreateTimer ¶
func (self Expanded) CreateTimer(time_sec Float.X, process_always bool, process_in_physics bool, ignore_time_scale bool) SceneTreeTimer.Instance
Returns a new graphics.gd/classdb/SceneTreeTimer. After 'time_sec' in seconds have passed, the timer will emit [Instance.OnScenetreetimer.Timeout] and will be automatically freed.
If 'process_always' is false, the timer will be paused when setting graphics.gd/classdb/SceneTree.Instance.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 graphics.gd/classdb/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:
Note: The timer is always updated after all of the nodes in the tree. A node's graphics.gd/classdb/Node.Instance.Process method would be called before the timer updates (or graphics.gd/classdb/Node.Instance.PhysicsProcess if 'process_in_physics' is set to true).
func (Expanded) GetMultiplayer ¶
func (self Expanded) GetMultiplayer(for_path string) MultiplayerAPI.Instance
Searches for the graphics.gd/classdb/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 Instance.SetMultiplayer.
func (Expanded) 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 (Expanded) SetMultiplayer ¶
func (self Expanded) SetMultiplayer(multiplayer MultiplayerAPI.Instance, root_path string)
Sets a custom graphics.gd/classdb/MultiplayerAPI with the given 'root_path' (controlling also the relative subpaths), or override the default one if 'root_path' is empty.
Note: No graphics.gd/classdb/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: Instance.SetMultiplayer should be called before the child nodes are ready at the given 'root_path'. If multiplayer nodes like graphics.gd/classdb/MultiplayerSpawner or graphics.gd/classdb/MultiplayerSynchronizer are added to the tree before the custom multiplayer API is set, they will not work.
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 [graphics.gd/classdb/Object.Instance.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 ¶
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 Instance.SetGroup and Instance.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 ¶
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.
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 graphics.gd/classdb/PackedScene and creating a new instance.
Returns [Ok] on success, [ErrCantOpen] if the 'path' cannot be loaded into a graphics.gd/classdb/PackedScene, or [ErrCantCreate] if that scene cannot be instantiated.
Note: See Instance.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 graphics.gd/classdb/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 Instance.ChangeSceneToPacked is called:
1. The current scene node is immediately removed from the tree. From that point, graphics.gd/classdb/Node.Instance.GetTree called on the current (outgoing) scene will return null. Instance.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. graphics.gd/classdb/Node.Instance.GetTree and Instance.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 graphics.gd/classdb/Node.Instance.QueueFree.
If you want to reliably access the new scene, await the Instance.OnSceneChanged signal.
func (Instance) CreateTimer ¶
func (self Instance) CreateTimer(time_sec Float.X) SceneTreeTimer.Instance
Returns a new graphics.gd/classdb/SceneTreeTimer. After 'time_sec' in seconds have passed, the timer will emit [Instance.OnScenetreetimer.Timeout] and will be automatically freed.
If 'process_always' is false, the timer will be paused when setting graphics.gd/classdb/SceneTree.Instance.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 graphics.gd/classdb/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:
Note: The timer is always updated after all of the nodes in the tree. A node's graphics.gd/classdb/Node.Instance.Process method would be called before the timer updates (or graphics.gd/classdb/Node.Instance.PhysicsProcess if 'process_in_physics' is set to true).
func (Instance) CreateTween ¶
Creates and returns a new graphics.gd/classdb/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 graphics.gd/classdb/Tween created using this method is not bound to any graphics.gd/classdb/Node. It may keep working until there is nothing left to animate. If you want the graphics.gd/classdb/Tween to be automatically killed when the graphics.gd/classdb/Node is freed, use graphics.gd/classdb/Node.Instance.CreateTween or graphics.gd/classdb/Tween.Instance.BindNode.
func (Instance) CurrentScene ¶
func (Instance) DebugCollisionsHint ¶
func (Instance) DebugNavigationHint ¶
func (Instance) DebugPathsHint ¶
func (Instance) EditedSceneRoot ¶
func (Instance) GetFirstNodeInGroup ¶
Returns the first graphics.gd/classdb/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 Instance.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 Instance.OnPhysicsFrame. For the number of frames rendered, see graphics.gd/classdb/Engine.GetProcessFrames.
func (Instance) GetMultiplayer ¶
func (self Instance) GetMultiplayer() MultiplayerAPI.Instance
Searches for the graphics.gd/classdb/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 Instance.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 [graphics.gd/classdb/Tween]s 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) MultiplayerPoll ¶
func (Instance) NotifyGroup ¶
Calls graphics.gd/classdb/Object.Instance.Notification with the given 'notification' to all nodes inside this tree added to the 'group'. See also Godot notifications and Instance.CallGroup and Instance.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 graphics.gd/classdb/Object.Instance.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 ¶
func (Instance) OnNodeConfigurationWarningChanged ¶
func (Instance) OnNodeRemoved ¶
func (Instance) OnNodeRenamed ¶
func (Instance) OnPhysicsFrame ¶
func (Instance) OnProcessFrame ¶
func (Instance) OnSceneChanged ¶
func (Instance) OnTreeChanged ¶
func (Instance) OnTreeProcessModeChanged ¶
func (Instance) PhysicsInterpolation ¶
func (Instance) QueueDelete ¶
Queues the given 'obj' to be deleted, calling its graphics.gd/classdb/Object.Instance.Free at the end of the current frame. This method is similar to graphics.gd/classdb/Node.Instance.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 ¶
func (Instance) ReloadCurrentScene ¶
Reloads the currently active scene, replacing Instance.CurrentScene with a new instance of its original graphics.gd/classdb/PackedScene.
Returns [Ok] on success, [ErrUnconfigured] if no Instance.CurrentScene is defined, [ErrCantOpen] if Instance.CurrentScene cannot be loaded into a graphics.gd/classdb/PackedScene, or [ErrCantCreate] if the scene cannot be instantiated.
func (Instance) SetAutoAcceptQuit ¶
func (Instance) SetCurrentScene ¶
func (Instance) SetDebugCollisionsHint ¶
func (Instance) SetDebugNavigationHint ¶
func (Instance) SetDebugPathsHint ¶
func (Instance) SetEditedSceneRoot ¶
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 Instance.CallGroup and Instance.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 graphics.gd/classdb/MultiplayerAPI with the given 'root_path' (controlling also the relative subpaths), or override the default one if 'root_path' is empty.
Note: No graphics.gd/classdb/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: Instance.SetMultiplayer should be called before the child nodes are ready at the given 'root_path'. If multiplayer nodes like graphics.gd/classdb/MultiplayerSpawner or graphics.gd/classdb/MultiplayerSynchronizer are added to the tree before the custom multiplayer API is set, they will not work.
func (Instance) SetMultiplayerPoll ¶
func (Instance) SetPhysicsInterpolation ¶
func (Instance) SetQuitOnGoBack ¶
func (Instance) UnloadCurrentScene ¶
func (self Instance) UnloadCurrentScene()
If a current scene is loaded, calling this method will unload it.