Documentation
¶
Overview ¶
Package SceneTree provides methods for working with SceneTree object instances.
Index ¶
- func Add(node Node.Any)
- type Advanced
- type Any
- type GroupCallFlags
- 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) ChangeSceneToFile(path string) error
- func (self Instance) ChangeSceneToPacked(packed_scene [1]gdclass.PackedScene) error
- func (self Instance) CreateTimer(time_sec Float.X) [1]gdclass.SceneTreeTimer
- func (self Instance) CreateTween() [1]gdclass.Tween
- func (self Instance) CurrentScene() [1]gdclass.Node
- func (self Instance) DebugCollisionsHint() bool
- func (self Instance) DebugNavigationHint() bool
- func (self Instance) DebugPathsHint() bool
- func (self Instance) EditedSceneRoot() [1]gdclass.Node
- func (self Instance) GetFirstNodeInGroup(group string) [1]gdclass.Node
- func (self Instance) GetFrame() int
- func (self Instance) GetMultiplayer() [1]gdclass.MultiplayerAPI
- func (self Instance) GetNodeCount() int
- func (self Instance) GetNodeCountInGroup(group string) int
- func (self Instance) GetNodesInGroup(group string) [][1]gdclass.Node
- func (self Instance) GetProcessedTweens() [][1]gdclass.Tween
- func (self Instance) HasGroup(name string) 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 [1]gdclass.Node))
- func (self Instance) OnNodeConfigurationWarningChanged(cb func(node [1]gdclass.Node))
- func (self Instance) OnNodeRemoved(cb func(node [1]gdclass.Node))
- func (self Instance) OnNodeRenamed(cb func(node [1]gdclass.Node))
- func (self Instance) OnPhysicsFrame(cb func())
- func (self Instance) OnProcessFrame(cb func())
- func (self Instance) OnTreeChanged(cb func())
- func (self Instance) OnTreeProcessModeChanged(cb func())
- 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() [1]gdclass.Window
- func (self Instance) SetAutoAcceptQuit(value bool)
- func (self Instance) SetCurrentScene(value [1]gdclass.Node)
- func (self Instance) SetDebugCollisionsHint(value bool)
- func (self Instance) SetDebugNavigationHint(value bool)
- func (self Instance) SetDebugPathsHint(value bool)
- func (self Instance) SetEditedSceneRoot(value [1]gdclass.Node)
- 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 [1]gdclass.MultiplayerAPI)
- func (self Instance) SetMultiplayerPoll(value 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) UnsafePointer() unsafe.Pointer
- 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 GroupCallFlags ¶
type GroupCallFlags = gdclass.SceneTreeGroupCallFlags //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 [method Object.call_deferred].*/ 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 [constant GROUP_CALL_DEFERRED] to work. [b]Note:[/b] 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 Instance ¶
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 [b]groups[/b]: 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.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsMainLoop ¶
func (Instance) AsSceneTree ¶
func (Instance) AutoAcceptQuit ¶
func (Instance) ChangeSceneToFile ¶
Changes the running scene to the one at the given [param path], after loading it into a [PackedScene] and creating a new instance. Returns [constant OK] on success, [constant ERR_CANT_OPEN] if the [param path] cannot be loaded into a [PackedScene], or [constant ERR_CANT_CREATE] if that scene cannot be instantiated. [b]Note:[/b] See [method change_scene_to_packed] for details on the order of operations.
func (Instance) ChangeSceneToPacked ¶
func (self Instance) ChangeSceneToPacked(packed_scene [1]gdclass.PackedScene) error
Changes the running scene to a new instance of the given [PackedScene] (which must be valid). Returns [constant OK] on success, [constant ERR_CANT_CREATE] if the scene cannot be instantiated, or [constant ERR_INVALID_PARAMETER] if the scene is invalid. [b]Note:[/b] Operations happen in the following order when [method change_scene_to_packed] is called: 1. The current scene node is immediately removed from the tree. From that point, [method Node.get_tree] called on the current (outgoing) scene will return [code]null[/code]. [member current_scene] will be [code]null[/code], 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. [method Node.get_tree] and [member current_scene] 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 [method Node.queue_free].
func (Instance) CreateTimer ¶
func (self Instance) CreateTimer(time_sec Float.X) [1]gdclass.SceneTreeTimer
Returns a new [SceneTreeTimer]. After [param time_sec] in seconds have passed, the timer will emit [signal SceneTreeTimer.timeout] and will be automatically freed. If [param process_always] is [code]false[/code], the timer will be paused when setting [member SceneTree.paused] to [code]true[/code]. If [param process_in_physics] is [code]true[/code], the timer will update at the end of the physics frame, instead of the process frame. If [param ignore_time_scale] is [code]true[/code], the timer will ignore [member Engine.time_scale] and update with the real, elapsed time. This method is commonly used to create a one-shot delay timer, as in the following example: [codeblocks] [gdscript] func some_function():
print("start") await get_tree().create_timer(1.0).timeout print("end")
[/gdscript] [csharp] public async Task SomeFunction()
{ GD.Print("start"); await ToSignal(GetTree().CreateTimer(1.0f), SceneTreeTimer.SignalName.Timeout); GD.Print("end"); }
[/csharp] [/codeblocks] [b]Note:[/b] The timer is always updated [i]after[/i] all of the nodes in the tree. A node's [method Node._process] method would be called before the timer updates (or [method Node._physics_process] if [param process_in_physics] is set to [code]true[/code]).
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 [enum Tween.TweenProcessMode]). [b]Note:[/b] 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 [method Node.create_tween] or [method Tween.bind_node].
func (Instance) CurrentScene ¶
func (Instance) DebugCollisionsHint ¶
func (Instance) DebugNavigationHint ¶
func (Instance) DebugPathsHint ¶
func (Instance) EditedSceneRoot ¶
func (Instance) GetFirstNodeInGroup ¶
Returns the first [Node] found inside the tree, that has been added to the given [param group], in scene hierarchy order. Returns [code]null[/code] if no match is found. See also [method get_nodes_in_group].
func (Instance) GetFrame ¶
Returns how many frames have been processed, since the application started. This is [i]not[/i] a measurement of elapsed time.
func (Instance) GetMultiplayer ¶
func (self Instance) GetMultiplayer() [1]gdclass.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. See [method set_multiplayer].
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 [Array] containing all nodes inside this tree, that have been added to the given [param group], in scene hierarchy order.
func (Instance) GetProcessedTweens ¶
Returns an [Array] of currently existing [Tween]s in the tree, including paused tweens.
func (Instance) HasGroup ¶
Returns [code]true[/code] if a node added to the given group [param name] exists in the tree.
func (Instance) MultiplayerPoll ¶
func (Instance) NotifyGroup ¶
Calls [method Object.notification] with the given [param notification] to all nodes inside this tree added to the [param group]. See also [url=$DOCS_URL/tutorials/best_practices/godot_notifications.html]Godot notifications[/url] and [method call_group] and [method set_group]. [b]Note:[/b] This method acts immediately on all selected nodes at once, which may cause stuttering in some performance-intensive situations.
func (Instance) NotifyGroupFlags ¶
Calls [method Object.notification] with the given [param notification] to all nodes inside this tree added to the [param group]. Use [param call_flags] to customize this method's behavior (see [enum GroupCallFlags]).
func (Instance) OnNodeAdded ¶
func (Instance) OnNodeConfigurationWarningChanged ¶
func (Instance) OnNodeRemoved ¶
func (Instance) OnNodeRenamed ¶
func (Instance) OnPhysicsFrame ¶
func (self Instance) OnPhysicsFrame(cb func())
func (Instance) OnProcessFrame ¶
func (self Instance) OnProcessFrame(cb func())
func (Instance) OnTreeChanged ¶
func (self Instance) OnTreeChanged(cb func())
func (Instance) OnTreeProcessModeChanged ¶
func (self Instance) OnTreeProcessModeChanged(cb func())
func (Instance) PhysicsInterpolation ¶
func (Instance) QueueDelete ¶
Queues the given [param obj] to be deleted, calling its [method Object.free] at the end of the current frame. This method is similar to [method Node.queue_free].
func (Instance) Quit ¶
func (self Instance) Quit()
Quits the application at the end of the current iteration, with the given [param exit_code]. By convention, an exit code of [code]0[/code] indicates success, whereas any other exit code indicates an error. For portability reasons, it should be between [code]0[/code] and [code]125[/code] (inclusive). [b]Note:[/b] On iOS this method doesn't work. Instead, as recommended by the [url=https://developer.apple.com/library/archive/qa/qa1561/_index.html]iOS Human Interface Guidelines[/url], the user is expected to close apps via the Home button.
func (Instance) QuitOnGoBack ¶
func (Instance) ReloadCurrentScene ¶
Reloads the currently active scene, replacing [member current_scene] with a new instance of its original [PackedScene]. Returns [constant OK] on success, [constant ERR_UNCONFIGURED] if no [member current_scene] is defined, [constant ERR_CANT_OPEN] if [member current_scene] cannot be loaded into a [PackedScene], or [constant ERR_CANT_CREATE] 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 [param property] to [param value] on all nodes inside this tree added to the given [param group]. Nodes that do not have the [param property] are ignored. See also [method call_group] and [method notify_group]. [b]Note:[/b] This method acts immediately on all selected nodes at once, which may cause stuttering in some performance-intensive situations. [b]Note:[/b] In C#, [param property] must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the [code]PropertyName[/code] class to avoid allocating a new [StringName] on each call.
func (Instance) SetGroupFlags ¶
Sets the given [param property] to [param value] on all nodes inside this tree added to the given [param group]. Nodes that do not have the [param property] are ignored. Use [param call_flags] to customize this method's behavior (see [enum GroupCallFlags]). [b]Note:[/b] In C#, [param property] must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the [code]PropertyName[/code] class to avoid allocating a new [StringName] on each call.
func (Instance) SetMultiplayer ¶
func (self Instance) SetMultiplayer(multiplayer [1]gdclass.MultiplayerAPI)
Sets a custom [MultiplayerAPI] with the given [param root_path] (controlling also the relative subpaths), or override the default one if [param root_path] is empty. [b]Note:[/b] No [MultiplayerAPI] must be configured for the subpath containing [param root_path], nested custom multiplayers are not allowed. I.e. if one is configured for [code]"/root/Foo"[/code] setting one for [code]"/root/Foo/Bar"[/code] will cause an error.
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.