SceneTree

package
v0.0.0-...-e1beaa7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 30 Imported by: 1

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(node Node.Any)

Add the given node to the scene tree.

func AddNamed

func AddNamed(name string, node Node.Any)

AddNamed adds the given node to the scene tree with the given name.

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 Any

type Any interface {
	gd.IsClass
	AsSceneTree() Instance
}

type Expanded

type Expanded [1]gdclass.SceneTree

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

func (self Expanded) Quit(exit_code int)

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

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

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 (self *Extension[T]) AsMainLoop() MainLoop.Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsSceneTree

func (self *Extension[T]) AsSceneTree() Instance

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

type ID Object.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.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.SceneTree

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

func Get(peer Node.Instance) Instance

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 New

func New() Instance

func (Instance) AsMainLoop

func (self Instance) AsMainLoop() MainLoop.Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsSceneTree

func (self Instance) AsSceneTree() Instance

func (Instance) AutoAcceptQuit

func (self Instance) AutoAcceptQuit() bool

func (Instance) CallGroup

func (self Instance) CallGroup(group string, method string, args ...any)

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

func (self Instance) CallGroupFlags(flags int, 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.

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

func (self Instance) ChangeSceneToFile(path string) error

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

func (self Instance) CreateTween() Tween.Instance

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 (self Instance) CurrentScene() Node.Instance

func (Instance) DebugCollisionsHint

func (self Instance) DebugCollisionsHint() bool

func (Instance) DebugNavigationHint

func (self Instance) DebugNavigationHint() bool

func (Instance) DebugPathsHint

func (self Instance) DebugPathsHint() bool

func (Instance) EditedSceneRoot

func (self Instance) EditedSceneRoot() Node.Instance

func (Instance) GetFirstNodeInGroup

func (self Instance) GetFirstNodeInGroup(group string) Node.Instance

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

func (self Instance) GetFrame() int

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

func (self Instance) GetNodeCount() int

Returns the number of nodes inside this tree.

func (Instance) GetNodeCountInGroup

func (self Instance) GetNodeCountInGroup(group string) int

Returns the number of nodes assigned to the given group.

func (Instance) GetNodesInGroup

func (self Instance) GetNodesInGroup(group string) []Node.Instance

Returns an slice containing all nodes inside this tree, that have been added to the given 'group', in scene hierarchy order.

func (Instance) GetProcessedTweens

func (self Instance) GetProcessedTweens() []Tween.Instance

Returns an slice of currently existing [graphics.gd/classdb/Tween]s in the tree, including paused tweens.

func (Instance) HasGroup

func (self Instance) HasGroup(name string) bool

Returns true if a node added to the given group 'name' exists in the tree.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) IsAccessibilityEnabled

func (self Instance) IsAccessibilityEnabled() bool

Returns true if accessibility features are enabled, and accessibility information updates are actively processed.

func (Instance) IsAccessibilitySupported

func (self Instance) IsAccessibilitySupported() bool

Returns true if accessibility features are supported by the OS and enabled in project settings.

func (Instance) MultiplayerPoll

func (self Instance) MultiplayerPoll() bool

func (Instance) NotifyGroup

func (self Instance) NotifyGroup(group string, notification int)

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

func (self Instance) NotifyGroupFlags(call_flags int, group string, notification int)

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 (self Instance) OnNodeAdded(cb func(node Node.Instance), flags ...Signal.Flags)

func (Instance) OnNodeConfigurationWarningChanged

func (self Instance) OnNodeConfigurationWarningChanged(cb func(node Node.Instance), flags ...Signal.Flags)

func (Instance) OnNodeRemoved

func (self Instance) OnNodeRemoved(cb func(node Node.Instance), flags ...Signal.Flags)

func (Instance) OnNodeRenamed

func (self Instance) OnNodeRenamed(cb func(node Node.Instance), flags ...Signal.Flags)

func (Instance) OnPhysicsFrame

func (self Instance) OnPhysicsFrame(cb func(), flags ...Signal.Flags)

func (Instance) OnProcessFrame

func (self Instance) OnProcessFrame(cb func(), flags ...Signal.Flags)

func (Instance) OnSceneChanged

func (self Instance) OnSceneChanged(cb func(), flags ...Signal.Flags)

func (Instance) OnTreeChanged

func (self Instance) OnTreeChanged(cb func(), flags ...Signal.Flags)

func (Instance) OnTreeProcessModeChanged

func (self Instance) OnTreeProcessModeChanged(cb func(), flags ...Signal.Flags)

func (Instance) Paused

func (self Instance) Paused() bool

func (Instance) PhysicsInterpolation

func (self Instance) PhysicsInterpolation() bool

func (Instance) QueueDelete

func (self Instance) QueueDelete(obj Object.Instance)

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 (self Instance) QuitOnGoBack() bool

func (Instance) ReloadCurrentScene

func (self Instance) ReloadCurrentScene() error

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

func (self Instance) Root() Window.Instance

func (Instance) SetAutoAcceptQuit

func (self Instance) SetAutoAcceptQuit(value bool)

func (Instance) SetCurrentScene

func (self Instance) SetCurrentScene(value Node.Instance)

func (Instance) SetDebugCollisionsHint

func (self Instance) SetDebugCollisionsHint(value bool)

func (Instance) SetDebugNavigationHint

func (self Instance) SetDebugNavigationHint(value bool)

func (Instance) SetDebugPathsHint

func (self Instance) SetDebugPathsHint(value bool)

func (Instance) SetEditedSceneRoot

func (self Instance) SetEditedSceneRoot(value Node.Instance)

func (Instance) SetGroup

func (self Instance) SetGroup(group string, property string, value any)

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

func (self Instance) SetGroupFlags(call_flags int, group string, property string, value any)

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 (self Instance) SetMultiplayerPoll(value bool)

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetPaused

func (self Instance) SetPaused(value bool)

func (Instance) SetPhysicsInterpolation

func (self Instance) SetPhysicsInterpolation(value bool)

func (Instance) SetQuitOnGoBack

func (self Instance) SetQuitOnGoBack(value bool)

func (Instance) UnloadCurrentScene

func (self Instance) UnloadCurrentScene()

If a current scene is loaded, calling this method will unload it.

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL