Class Node
- Namespace
- Godot
- Assembly
- GodotSharp.dll
Nodes are Godot's building blocks. They can be assigned as the child of another node, resulting in a tree arrangement. A given node can contain any number of nodes as children with the requirement that all siblings (direct children of a node) should have unique names.
A tree of nodes is called a scene. Scenes can be saved to the disk and then instantiated into other scenes. This allows for very high flexibility in the architecture and data model of Godot projects.
Scene tree: The SceneTree contains the active tree of nodes. When a node is added to the scene tree, it receives the NotificationEnterTree notification and its _EnterTree() callback is triggered. Child nodes are always added after their parent node, i.e. the _EnterTree() callback of a parent node will be triggered before its child's.
Once all nodes have been added in the scene tree, they receive the NotificationReady notification and their respective _Ready() callbacks are triggered. For groups of nodes, the _Ready() callback is called in reverse order, starting with the children and moving up to the parent nodes.
This means that when adding a node to the scene tree, the following order will be used for the callbacks: _EnterTree() of the parent, _EnterTree() of the children, _Ready() of the children and finally _Ready() of the parent (recursively for the entire scene tree).
Processing: Nodes can override the "process" state, so that they receive a callback on each frame requesting them to process (do something). Normal processing (callback _Process(double), toggled with SetProcess(bool)) happens as fast as possible and is dependent on the frame rate, so the processing time delta (in seconds) is passed as an argument. Physics processing (callback _PhysicsProcess(double), toggled with SetPhysicsProcess(bool)) happens a fixed number of times per second (60 by default) and is useful for code related to the physics engine.
Nodes can also process input events. When present, the _Input(InputEvent) function will be called for each input that the program receives. In many cases, this can be overkill (unless used for simple projects), and the _UnhandledInput(InputEvent) function might be preferred; it is called when the input event was not handled by anyone else (typically, GUI Control nodes), ensuring that the node only receives the events that were meant for it.
To keep track of the scene hierarchy (especially when instantiating scenes into other scenes), an "owner" can be set for the node with the Owner property. This keeps track of who instantiated what. This is mostly useful when writing editors and tools, though.
Finally, when a node is freed with Free() or QueueFree(), it will also free all its children.
Groups: Nodes can be added to as many groups as you want to be easy to manage, you could create groups like "enemies" or "collectables" for example, depending on your game. See AddToGroup(StringName, bool), IsInGroup(StringName) and RemoveFromGroup(StringName). You can then retrieve all nodes in these groups, iterate them and even call methods on groups via the methods on SceneTree.
Networking with nodes: After connecting to a server (or making one, see ENetMultiplayerPeer), it is possible to use the built-in RPC (remote procedure call) system to communicate over the network. By calling Rpc(StringName, params Variant[]) with a method name, it will be called locally and in all connected peers (peers = clients and the server that accepts connections). To identify which node receives the RPC call, Godot will use its NodePath (make sure node names are the same on all peers). Also, take a look at the high-level networking tutorial and corresponding demos.
Note: The script
property is part of the GodotObject class, not Node. It isn't exposed like most properties but does have a setter and getter (see SetScript(Variant) and GetScript()).
public class Node : GodotObject, IDisposable
- Inheritance
-
Node
- Implements
- Derived
- Inherited Members
Constructors
Node()
public Node()
Fields
NotificationApplicationFocusIn
Notification received from the OS when the application is focused, i.e. when changing the focus from the OS desktop or a thirdparty application to any open window of the Godot instance.
Implemented on desktop and mobile platforms.
public const long NotificationApplicationFocusIn = 2016
Field Value
NotificationApplicationFocusOut
Notification received from the OS when the application is defocused, i.e. when changing the focus from any open window of the Godot instance to the OS desktop or a thirdparty application.
Implemented on desktop and mobile platforms.
public const long NotificationApplicationFocusOut = 2017
Field Value
NotificationApplicationPaused
Notification received from the OS when the application is paused.
Specific to the Android and iOS platforms.
Note: On iOS, you only have approximately 5 seconds to finish a task started by this signal. If you go over this allotment, iOS will kill the app instead of pausing it.
public const long NotificationApplicationPaused = 2015
Field Value
NotificationApplicationResumed
Notification received from the OS when the application is resumed.
Specific to the Android and iOS platforms.
public const long NotificationApplicationResumed = 2014
Field Value
NotificationChildOrderChanged
Notification received when the list of children is changed. This happens when child nodes are added, moved or removed.
public const long NotificationChildOrderChanged = 24
Field Value
NotificationCrash
Notification received from Godot's crash handler when the engine is about to crash.
Implemented on desktop platforms, if the crash handler is enabled.
public const long NotificationCrash = 2012
Field Value
NotificationDisabled
Notification received when the node is disabled. See Disabled.
public const long NotificationDisabled = 28
Field Value
NotificationDragBegin
Notification received when a drag operation begins. All nodes receive this notification, not only the dragged one.
Can be triggered either by dragging a Control that provides drag data (see _GetDragData(Vector2)) or using ForceDrag(Variant, Control).
Use GuiGetDragData() to get the dragged data.
public const long NotificationDragBegin = 21
Field Value
NotificationDragEnd
Notification received when a drag operation ends.
Use GuiIsDragSuccessful() to check if the drag succeeded.
public const long NotificationDragEnd = 22
Field Value
NotificationEditorPostSave
Notification received right after the scene with the node is saved in the editor. This notification is only sent in the Godot editor and will not occur in exported projects.
public const long NotificationEditorPostSave = 9002
Field Value
NotificationEditorPreSave
Notification received right before the scene with the node is saved in the editor. This notification is only sent in the Godot editor and will not occur in exported projects.
public const long NotificationEditorPreSave = 9001
Field Value
NotificationEnabled
Notification received when the node is enabled again after being disabled. See Disabled.
public const long NotificationEnabled = 29
Field Value
NotificationEnterTree
Notification received when the node enters a SceneTree. See _EnterTree().
This notification is received before the related TreeEntered signal.
public const long NotificationEnterTree = 10
Field Value
NotificationExitTree
Notification received when the node is about to exit a SceneTree. See _ExitTree().
This notification is received after the related TreeExiting signal.
public const long NotificationExitTree = 11
Field Value
NotificationInternalPhysicsProcess
Notification received from the tree every physics frame when IsPhysicsProcessingInternal() returns true.
public const long NotificationInternalPhysicsProcess = 26
Field Value
NotificationInternalProcess
Notification received from the tree every rendered frame when IsProcessingInternal() returns true.
public const long NotificationInternalProcess = 25
Field Value
NotificationMovedInParent
[Obsolete("This notification is no longer sent by the engine. Use 'Godot.Node.NotificationChildOrderChanged' instead.")]
public const long NotificationMovedInParent = 12
Field Value
NotificationOsImeUpdate
Notification received from the OS when an update of the Input Method Engine occurs (e.g. change of IME cursor position or composition string).
Implemented only on macOS.
public const long NotificationOsImeUpdate = 2013
Field Value
NotificationOsMemoryWarning
Notification received from the OS when the application is exceeding its allocated memory.
Implemented only on iOS.
public const long NotificationOsMemoryWarning = 2009
Field Value
NotificationParented
Notification received when the node is set as a child of another node (see AddChild(Node, bool, InternalMode) and AddSibling(Node, bool)).
Note: This does not mean that the node entered the SceneTree.
public const long NotificationParented = 18
Field Value
NotificationPathRenamed
Notification received when the node's Name or one of its ancestors' Name is changed. This notification is not received when the node is removed from the SceneTree.
public const long NotificationPathRenamed = 23
Field Value
NotificationPaused
Notification received when the node is paused. See ProcessMode.
public const long NotificationPaused = 14
Field Value
NotificationPhysicsProcess
Notification received from the tree every physics frame when IsPhysicsProcessing() returns true. See _PhysicsProcess(double).
public const long NotificationPhysicsProcess = 16
Field Value
NotificationPostEnterTree
Notification received when the node enters the tree, just before NotificationReady may be received. Unlike the latter, it is sent every time the node enters tree, not just once.
public const long NotificationPostEnterTree = 27
Field Value
NotificationProcess
Notification received from the tree every rendered frame when IsProcessing() returns true. See _Process(double).
public const long NotificationProcess = 17
Field Value
NotificationReady
Notification received when the node is ready. See _Ready().
public const long NotificationReady = 13
Field Value
NotificationResetPhysicsInterpolation
Notification received when ResetPhysicsInterpolation() is called on the node or its ancestors.
public const long NotificationResetPhysicsInterpolation = 2001
Field Value
NotificationSceneInstantiated
Notification received only by the newly instantiated scene root node, when Instantiate(GenEditState) is completed.
public const long NotificationSceneInstantiated = 20
Field Value
NotificationTextServerChanged
Notification received when the TextServer is changed.
public const long NotificationTextServerChanged = 2018
Field Value
NotificationTranslationChanged
Notification received when translations may have changed. Can be triggered by the user changing the locale, changing AutoTranslateMode or when the node enters the scene tree. Can be used to respond to language changes, for example to change the UI strings on the fly. Useful when working with the built-in translation support, like Tr(StringName, StringName).
Note: This notification is received alongside NotificationEnterTree, so if you are instantiating a scene, the child nodes will not be initialized yet. You can use it to setup translations for this node, child nodes created from script, or if you want to access child nodes added in the editor, make sure the node is ready using IsNodeReady().
func _notification(what):
if what == NOTIFICATION_TRANSLATION_CHANGED:
if not is_node_ready():
await ready # Wait until ready signal.
$Label.text = atr("%d Bananas") % banana_counter
public const long NotificationTranslationChanged = 2010
Field Value
NotificationUnparented
Notification received when the parent node calls RemoveChild(Node) on this node.
Note: This does not mean that the node exited the SceneTree.
public const long NotificationUnparented = 19
Field Value
NotificationUnpaused
Notification received when the node is unpaused. See ProcessMode.
public const long NotificationUnpaused = 15
Field Value
NotificationVpMouseEnter
Notification received when the mouse cursor enters the Viewport's visible area, that is not occluded behind other Controls or Windows, provided its GuiDisableInput is false and regardless if it's currently focused or not.
public const long NotificationVpMouseEnter = 1010
Field Value
NotificationVpMouseExit
Notification received when the mouse cursor leaves the Viewport's visible area, that is not occluded behind other Controls or Windows, provided its GuiDisableInput is false and regardless if it's currently focused or not.
public const long NotificationVpMouseExit = 1011
Field Value
NotificationWMAbout
Notification received from the OS when a request for "About" information is sent.
Implemented only on macOS.
public const long NotificationWMAbout = 2011
Field Value
NotificationWMCloseRequest
Notification received from the OS when a close request is sent (e.g. closing the window with a "Close" button or Alt + F4).
Implemented on desktop platforms.
public const long NotificationWMCloseRequest = 1006
Field Value
NotificationWMDpiChange
Notification received from the OS when the screen's dots per inch (DPI) scale is changed. Only implemented on macOS.
public const long NotificationWMDpiChange = 1009
Field Value
NotificationWMGoBackRequest
Notification received from the OS when a go back request is sent (e.g. pressing the "Back" button on Android).
Implemented only on Android.
public const long NotificationWMGoBackRequest = 1007
Field Value
NotificationWMMouseEnter
Notification received when the mouse enters the window.
Implemented for embedded windows and on desktop and web platforms.
public const long NotificationWMMouseEnter = 1002
Field Value
NotificationWMMouseExit
Notification received when the mouse leaves the window.
Implemented for embedded windows and on desktop and web platforms.
public const long NotificationWMMouseExit = 1003
Field Value
NotificationWMSizeChanged
Notification received when the window is resized.
Note: Only the resized Window node receives this notification, and it's not propagated to the child nodes.
public const long NotificationWMSizeChanged = 1008
Field Value
NotificationWMWindowFocusIn
Notification received from the OS when the node's Window ancestor is focused. This may be a change of focus between two windows of the same engine instance, or from the OS desktop or a third-party application to a window of the game (in which case NotificationApplicationFocusIn is also received).
A Window node receives this notification when it is focused.
public const long NotificationWMWindowFocusIn = 1004
Field Value
NotificationWMWindowFocusOut
Notification received from the OS when the node's Window ancestor is defocused. This may be a change of focus between two windows of the same engine instance, or from a window of the game to the OS desktop or a third-party application (in which case NotificationApplicationFocusOut is also received).
A Window node receives this notification when it is defocused.
public const long NotificationWMWindowFocusOut = 1005
Field Value
Properties
AutoTranslateMode
Defines if any text should automatically change to its translated version depending on the current locale (for nodes such as Label, RichTextLabel, Window, etc.). Also decides if the node's strings should be parsed for POT generation.
Note: For the root node, auto translate mode can also be set via ProjectSettings.internationalization/rendering/root_node_auto_translate
.
public Node.AutoTranslateModeEnum AutoTranslateMode { get; set; }
Property Value
EditorDescription
An optional description to the node. It will be displayed as a tooltip when hovering over the node in the editor's Scene dock.
public string EditorDescription { get; set; }
Property Value
Multiplayer
The MultiplayerApi instance associated with this node. See GetMultiplayer(NodePath).
Note: Renaming the node, or moving it in the tree, will not move the MultiplayerApi to the new path, you will have to update this manually.
public MultiplayerApi Multiplayer { get; }
Property Value
Name
The name of the node. This name must be unique among the siblings (other child nodes from the same parent). When set to an existing sibling's name, the node is automatically renamed.
Note: When changing the name, the following characters will be replaced with an underscore: (.
:
@
/
"
%
). In particular, the @
character is reserved for auto-generated names. See also String.validate_node_name
.
public StringName Name { get; set; }
Property Value
Owner
The owner of this node. The owner must be an ancestor of this node. When packing the owner node in a PackedScene, all the nodes it owns are also saved with it.
Note: In the editor, nodes not owned by the scene root are usually not displayed in the Scene dock, and will not be saved. To prevent this, remember to set the owner after calling AddChild(Node, bool, InternalMode). See also (see UniqueNameInOwner)
public Node Owner { get; set; }
Property Value
PhysicsInterpolationMode
Allows enabling or disabling physics interpolation per node, offering a finer grain of control than turning physics interpolation on and off globally. See ProjectSettings.physics/common/physics_interpolation
and PhysicsInterpolation for the global setting.
Note: When teleporting a node to a distant position you should temporarily disable interpolation with ResetPhysicsInterpolation().
public Node.PhysicsInterpolationModeEnum PhysicsInterpolationMode { get; set; }
Property Value
ProcessMode
The node's processing behavior (see Node.ProcessModeEnum). To check if the node can process in its current mode, use CanProcess().
public Node.ProcessModeEnum ProcessMode { get; set; }
Property Value
ProcessPhysicsPriority
Similar to ProcessPriority but for NotificationPhysicsProcess, _PhysicsProcess(double) or the internal version.
public int ProcessPhysicsPriority { get; set; }
Property Value
ProcessPriority
The node's execution order of the process callbacks (_Process(double), _PhysicsProcess(double), and internal processing). Nodes whose priority value is lower call their process callbacks first, regardless of tree order.
public int ProcessPriority { get; set; }
Property Value
ProcessThreadGroup
Set the process thread group for this node (basically, whether it receives NotificationProcess, NotificationPhysicsProcess, _Process(double) or _PhysicsProcess(double) (and the internal versions) on the main thread or in a sub-thread.
By default, the thread group is Inherit, which means that this node belongs to the same thread group as the parent node. The thread groups means that nodes in a specific thread group will process together, separate to other thread groups (depending on ProcessThreadGroupOrder). If the value is set is SubThread, this thread group will occur on a sub thread (not the main thread), otherwise if set to MainThread it will process on the main thread. If there is not a parent or grandparent node set to something other than inherit, the node will belong to the default thread group. This default group will process on the main thread and its group order is 0.
During processing in a sub-thread, accessing most functions in nodes outside the thread group is forbidden (and it will result in an error in debug mode). Use CallDeferred(StringName, params Variant[]), CallThreadSafe(StringName, params Variant[]), CallDeferredThreadGroup(StringName, params Variant[]) and the likes in order to communicate from the thread groups to the main thread (or to other thread groups).
To better understand process thread groups, the idea is that any node set to any other value than Inherit will include any child (and grandchild) nodes set to inherit into its process thread group. This means that the processing of all the nodes in the group will happen together, at the same time as the node including them.
public Node.ProcessThreadGroupEnum ProcessThreadGroup { get; set; }
Property Value
ProcessThreadGroupOrder
Change the process thread group order. Groups with a lesser order will process before groups with a greater order. This is useful when a large amount of nodes process in sub thread and, afterwards, another group wants to collect their result in the main thread, as an example.
public int ProcessThreadGroupOrder { get; set; }
Property Value
ProcessThreadMessages
Set whether the current thread group will process messages (calls to CallDeferredThreadGroup(StringName, params Variant[]) on threads), and whether it wants to receive them during regular process or physics process callbacks.
public Node.ProcessThreadMessagesEnum ProcessThreadMessages { get; set; }
Property Value
SceneFilePath
The original scene's file path, if the node has been instantiated from a PackedScene file. Only scene root nodes contains this.
public string SceneFilePath { get; set; }
Property Value
UniqueNameInOwner
If true, the node can be accessed from any node sharing the same Owner or from the Owner itself, with special %Name
syntax in GetNode(NodePath).
Note: If another node with the same Owner shares the same Name as this node, the other node will no longer be accessible as unique.
public bool UniqueNameInOwner { get; set; }
Property Value
Methods
AddChild(Node, bool, InternalMode)
Adds a child node
. Nodes can have any number of children, but every child must have a unique name. Child nodes are automatically deleted when the parent node is deleted, so an entire scene can be removed by deleting its topmost node.
If forceReadableName
is true, improves the readability of the added node
. If not named, the node
is renamed to its type, and if it shares Name with a sibling, a number is suffixed more appropriately. This operation is very slow. As such, it is recommended leaving this to false, which assigns a dummy name featuring @
in both situations.
If internal
is different than Disabled, the child will be added as internal node. These nodes are ignored by methods like GetChildren(bool), unless their parameter include_internal
is true. The intended usage is to hide the internal nodes from the user, so the user won't accidentally delete or modify them. Used by some GUI nodes, e.g. ColorPicker. See Node.InternalMode for available modes.
Note: If node
already has a parent, this method will fail. Use RemoveChild(Node) first to remove node
from its current parent. For example:
Node childNode = GetChild(0);
if (childNode.GetParent() != null)
{
childNode.GetParent().RemoveChild(childNode);
}
AddChild(childNode);
If you need the child node to be added below a specific node in the list of children, use AddSibling(Node, bool) instead of this method.
Note: If you want a child to be persisted to a PackedScene, you must set Owner in addition to calling AddChild(Node, bool, InternalMode). This is typically relevant for tool scripts and editor plugins. If AddChild(Node, bool, InternalMode) is called without setting Owner, the newly added Node will not be visible in the scene tree, though it will be visible in the 2D/3D view.
public void AddChild(Node node, bool forceReadableName = false, Node.InternalMode @internal = InternalMode.Disabled)
Parameters
node
NodeforceReadableName
boolinternal
Node.InternalMode
AddSibling(Node, bool)
Adds a sibling
node to this node's parent, and moves the added sibling right below this node.
If forceReadableName
is true, improves the readability of the added sibling
. If not named, the sibling
is renamed to its type, and if it shares Name with a sibling, a number is suffixed more appropriately. This operation is very slow. As such, it is recommended leaving this to false, which assigns a dummy name featuring @
in both situations.
Use AddChild(Node, bool, InternalMode) instead of this method if you don't need the child node to be added below a specific node in the list of children.
Note: If this node is internal, the added sibling will be internal too (see AddChild(Node, bool, InternalMode)'s internal
parameter).
public void AddSibling(Node sibling, bool forceReadableName = false)
Parameters
AddToGroup(StringName, bool)
Adds the node to the group
. Groups can be helpful to organize a subset of nodes, for example "enemies"
or "collectables"
. See notes in the description, and the group methods in SceneTree.
If persistent
is true, the group will be stored when saved inside a PackedScene. All groups created and displayed in the Node dock are persistent.
Note: To improve performance, the order of group names is not guaranteed and may vary between project runs. Therefore, do not rely on the group order.
Note: SceneTree's group methods will not work on this node if not inside the tree (see IsInsideTree()).
public void AddToGroup(StringName group, bool persistent = false)
Parameters
group
StringNamepersistent
bool
Atr(string, StringName)
Translates a message
, using the translation catalogs configured in the Project Settings. Further context
can be specified to help with the translation. Note that most Control nodes automatically translate their strings, so this method is mostly useful for formatted strings or custom drawn text.
This method works the same as Tr(StringName, StringName), with the addition of respecting the AutoTranslateMode state.
If CanTranslateMessages() is false, or no translation is available, this method returns the message
without changes. See SetMessageTranslation(bool).
For detailed examples, see Internationalizing games.
public string Atr(string message, StringName context = null)
Parameters
message
stringcontext
StringName
Returns
AtrN(string, StringName, int, StringName)
Translates a message
or pluralMessage
, using the translation catalogs configured in the Project Settings. Further context
can be specified to help with the translation.
This method works the same as TrN(StringName, StringName, int, StringName), with the addition of respecting the AutoTranslateMode state.
If CanTranslateMessages() is false, or no translation is available, this method returns message
or pluralMessage
, without changes. See SetMessageTranslation(bool).
The n
is the number, or amount, of the message's subject. It is used by the translation system to fetch the correct plural form for the current language.
For detailed examples, see Localization using gettext.
Note: Negative and float numbers may not properly apply to some countable subjects. It's recommended to handle these cases with Atr(string, StringName).
public string AtrN(string message, StringName pluralMessage, int n, StringName context = null)
Parameters
message
stringpluralMessage
StringNamen
intcontext
StringName
Returns
CallDeferredThreadGroup(StringName, params Variant[])
This function is similar to CallDeferred(StringName, params Variant[]) except that the call will take place when the node thread group is processed. If the node thread group processes in sub-threads, then the call will be done on that thread, right before NotificationProcess or NotificationPhysicsProcess, the _Process(double) or _PhysicsProcess(double) or their internal versions are called.
public Variant CallDeferredThreadGroup(StringName method, params Variant[] args)
Parameters
method
StringNameargs
Variant[]
Returns
CallThreadSafe(StringName, params Variant[])
This function ensures that the calling of this function will succeed, no matter whether it's being done from a thread or not. If called from a thread that is not allowed to call the function, the call will become deferred. Otherwise, the call will go through directly.
public Variant CallThreadSafe(StringName method, params Variant[] args)
Parameters
method
StringNameargs
Variant[]
Returns
CanProcess()
Returns true if the node can receive processing notifications and input callbacks (NotificationProcess, _Input(InputEvent), etc.) from the SceneTree and Viewport. The returned value depends on ProcessMode:
- If set to Pausable, returns true when the game is processing, i.e. Paused is false;
- If set to WhenPaused, returns true when the game is paused, i.e. Paused is true;
- If set to Always, always returns true;
- If set to Disabled, always returns false;
- If set to Inherit, use the parent node's ProcessMode to determine the result.
If the node is not inside the tree, returns false no matter the value of ProcessMode.
public bool CanProcess()
Returns
CreateTween()
Creates a new Tween and binds it to this node.
This is the equivalent of doing:
GetTree().CreateTween().BindNode(this);
The Tween will start automatically on the next process frame or physics frame (depending on Tween.TweenProcessMode). See BindNode(Node) for more info on Tweens bound to nodes.
Note: The method can still be used when the node is not inside SceneTree. It can fail in an unlikely case of using a custom MainLoop.
public Tween CreateTween()
Returns
Duplicate(int)
Duplicates the node, returning a new node with all of its properties, signals and groups copied from the original. The behavior can be tweaked through the flags
(see Node.DuplicateFlags).
Note: For nodes with a Script attached, if GodotObject() has been defined with required parameters, the duplicated node will not have a Script.
public Node Duplicate(int flags = 15)
Parameters
flags
int
Returns
FindChild(string, bool, bool)
Finds the first descendant of this node whose Name matches pattern
, returning null if no match is found. The matching is done against node names, not their paths, through String.match
. As such, it is case-sensitive, "*"
matches zero or more characters, and "?"
matches any single character.
If recursive
is false, only this node's direct children are checked. Nodes are checked in tree order, so this node's first direct child is checked first, then its own direct children, etc., before moving to the second direct child, and so on. Internal children are also included in the search (see internal
parameter in AddChild(Node, bool, InternalMode)).
If owned
is true, only descendants with a valid Owner node are checked.
Note: This method can be very slow. Consider storing a reference to the found node in a variable. Alternatively, use GetNode(NodePath) with unique names (see UniqueNameInOwner).
Note: To find all descendant nodes matching a pattern or a class type, see FindChildren(string, string, bool, bool).
public Node FindChild(string pattern, bool recursive = true, bool owned = true)
Parameters
Returns
FindChildren(string, string, bool, bool)
Finds all descendants of this node whose names match pattern
, returning an empty Array if no match is found. The matching is done against node names, not their paths, through String.match
. As such, it is case-sensitive, "*"
matches zero or more characters, and "?"
matches any single character.
If type
is not empty, only ancestors inheriting from type
are included (see IsClass(string)).
If recursive
is false, only this node's direct children are checked. Nodes are checked in tree order, so this node's first direct child is checked first, then its own direct children, etc., before moving to the second direct child, and so on. Internal children are also included in the search (see internal
parameter in AddChild(Node, bool, InternalMode)).
If owned
is true, only descendants with a valid Owner node are checked.
Note: This method can be very slow. Consider storing references to the found nodes in a variable.
Note: To find a single descendant node matching a pattern, see FindChild(string, bool, bool).
public Array<Node> FindChildren(string pattern, string type = "", bool recursive = true, bool owned = true)
Parameters
Returns
FindParent(string)
Finds the first ancestor of this node whose Name matches pattern
, returning null if no match is found. The matching is done through String.match
. As such, it is case-sensitive, "*"
matches zero or more characters, and "?"
matches any single character. See also FindChild(string, bool, bool) and FindChildren(string, string, bool, bool).
Note: As this method walks upwards in the scene tree, it can be slow in large, deeply nested nodes. Consider storing a reference to the found node in a variable. Alternatively, use GetNode(NodePath) with unique names (see UniqueNameInOwner).
public Node FindParent(string pattern)
Parameters
pattern
string
Returns
GetChild(int, bool)
Fetches a child node by its index. Each child node has an index relative its siblings (see GetIndex(bool)). The first child is at index 0. Negative values can also be used to start from the end of the list. This method can be used in combination with GetChildCount(bool) to iterate over this node's children. If no child exists at the given index, this method returns null and an error is generated.
If includeInternal
is false, internal children are ignored (see AddChild(Node, bool, InternalMode)'s internal
parameter).
# Assuming the following are children of this node, in order:
# First, Middle, Last.
var a = get_child(0).name # a is "First"
var b = get_child(1).name # b is "Middle"
var b = get_child(2).name # b is "Last"
var c = get_child(-1).name # c is "Last"
Note: To fetch a node by NodePath, use GetNode(NodePath).
public Node GetChild(int idx, bool includeInternal = false)
Parameters
Returns
GetChildCount(bool)
Returns the number of children of this node.
If includeInternal
is false, internal children are not counted (see AddChild(Node, bool, InternalMode)'s internal
parameter).
public int GetChildCount(bool includeInternal = false)
Parameters
includeInternal
bool
Returns
GetChildOrNull<T>(int, bool)
Returns a child node by its index (see GetChildCount(bool)). This method is often used for iterating all children of a node. Negative indices access the children from the last one. To access a child node via its name, use GetNode(NodePath).
public T GetChildOrNull<T>(int idx, bool includeInternal = false) where T : class
Parameters
idx
intChild index.
includeInternal
boolIf false, internal children are skipped (see
internal
parameter in AddChild(Node, bool, InternalMode)).
Returns
Type Parameters
T
The type to cast to. Should be a descendant of Node.
- See Also
GetChild<T>(int, bool)
Returns a child node by its index (see GetChildCount(bool)). This method is often used for iterating all children of a node. Negative indices access the children from the last one. To access a child node via its name, use GetNode(NodePath).
public T GetChild<T>(int idx, bool includeInternal = false) where T : class
Parameters
idx
intChild index.
includeInternal
boolIf false, internal children are skipped (see
internal
parameter in AddChild(Node, bool, InternalMode)).
Returns
- T
The child Node at the given index
idx
.
Type Parameters
T
The type to cast to. Should be a descendant of Node.
Exceptions
- InvalidCastException
The fetched node can't be casted to the given type
T
.
- See Also
GetChildren(bool)
Returns all children of this node inside an Array.
If includeInternal
is false, excludes internal children from the returned array (see AddChild(Node, bool, InternalMode)'s internal
parameter).
public Array<Node> GetChildren(bool includeInternal = false)
Parameters
includeInternal
bool
Returns
GetGroups()
Returns an Array of group names that the node has been added to.
Note: To improve performance, the order of group names is not guaranteed and may vary between project runs. Therefore, do not rely on the group order.
Note: This method may also return some group names starting with an underscore (_
). These are internally used by the engine. To avoid conflicts, do not use custom groups starting with underscores. To exclude internal groups, see the following code snippet:
// Stores the node's non-internal groups only (as a List of StringNames).
List<string> nonInternalGroups = new List<string>();
foreach (string group in GetGroups())
{
if (!group.BeginsWith("_"))
nonInternalGroups.Add(group);
}
public Array<StringName> GetGroups()
Returns
GetIndex(bool)
Returns this node's order among its siblings. The first node's index is 0
. See also GetChild(int, bool).
If includeInternal
is false, returns the index ignoring internal children. The first, non-internal child will have an index of 0
(see AddChild(Node, bool, InternalMode)'s internal
parameter).
public int GetIndex(bool includeInternal = false)
Parameters
includeInternal
bool
Returns
GetLastExclusiveWindow()
Returns the Window that contains this node, or the last exclusive child in a chain of windows starting with the one that contains this node.
public Window GetLastExclusiveWindow()
Returns
GetMultiplayerAuthority()
Returns the peer ID of the multiplayer authority for this node. See SetMultiplayerAuthority(int, bool).
public int GetMultiplayerAuthority()
Returns
GetNode(NodePath)
Fetches a node. The NodePath can either be a relative path (from this node), or an absolute path (from the Root) to a node. If path
does not point to a valid node, generates an error and returns null. Attempts to access methods on the return value will result in an "Attempt to call <method> on a null instance." error.
Note: Fetching by absolute path only works when the node is inside the scene tree (see IsInsideTree()).
Example: Assume this method is called from the Character node, inside the following tree:
┖╴root
┠╴Character (you are here!)
┃ ┠╴Sword
┃ ┖╴Backpack
┃ ┖╴Dagger
┠╴MyGame
┖╴Swamp
┠╴Alligator
┠╴Mosquito
┖╴Goblin
The following calls will return a valid node:
GetNode("Sword");
GetNode("Backpack/Dagger");
GetNode("../Swamp/Alligator");
GetNode("/root/MyGame");
public Node GetNode(NodePath path)
Parameters
path
NodePath
Returns
GetNodeAndResource(NodePath)
Fetches a node and its most nested resource as specified by the NodePath's subname. Returns an Array of size 3
where:
- Element 0
is the Node, or null if not found;
- Element 1
is the subname's last nested Resource, or null if not found;
- Element 2
is the remaining NodePath, referring to an existing, non-Resource property (see GetIndexed(NodePath)).
Example: Assume that the child's Texture has been assigned a AtlasTexture:
var a = GetNodeAndResource(NodePath("Area2D/Sprite2D"));
GD.Print(a[0].Name); // Prints Sprite2D
GD.Print(a[1]); // Prints <null>
GD.Print(a[2]); // Prints ^"
var b = GetNodeAndResource(NodePath("Area2D/Sprite2D:texture:atlas"));
GD.Print(b[0].name); // Prints Sprite2D
GD.Print(b[1].get_class()); // Prints AtlasTexture
GD.Print(b[2]); // Prints ^""
var c = GetNodeAndResource(NodePath("Area2D/Sprite2D:texture:atlas:region"));
GD.Print(c[0].name); // Prints Sprite2D
GD.Print(c[1].get_class()); // Prints AtlasTexture
GD.Print(c[2]); // Prints ^":region"
public Array GetNodeAndResource(NodePath path)
Parameters
path
NodePath
Returns
GetNodeOrNull(NodePath)
Fetches a node by NodePath. Similar to GetNode(NodePath), but does not generate an error if path
does not point to a valid node.
public Node GetNodeOrNull(NodePath path)
Parameters
path
NodePath
Returns
GetNodeOrNull<T>(NodePath)
Similar to GetNode(NodePath), but does not log an error if path
does not point to a valid Node.
public T GetNodeOrNull<T>(NodePath path) where T : class
Parameters
path
NodePathThe path to the node to fetch.
Returns
Type Parameters
T
The type to cast to. Should be a descendant of Node.
Examples
Example: Assume your current node is Character and the following tree:
/root
/root/Character
/root/Character/Sword
/root/Character/Backpack/Dagger
/root/MyGame
/root/Swamp/Alligator
/root/Swamp/Mosquito
/root/Swamp/Goblin
Possible paths are:
GetNode("Sword");
GetNode("Backpack/Dagger");
GetNode("../Swamp/Alligator");
GetNode("/root/MyGame");
- See Also
GetNode<T>(NodePath)
Fetches a node. The NodePath can be either a relative path (from the current node) or an absolute path (in the scene tree) to a node. If the path does not exist, a null instance is returned and an error is logged. Attempts to access methods on the return value will result in an "Attempt to call <method> on a null instance." error. Note: Fetching absolute paths only works when the node is inside the scene tree (see IsInsideTree()).
public T GetNode<T>(NodePath path) where T : class
Parameters
path
NodePathThe path to the node to fetch.
Returns
- T
The Node at the given
path
.
Type Parameters
T
The type to cast to. Should be a descendant of Node.
Examples
Example: Assume your current node is Character and the following tree:
/root
/root/Character
/root/Character/Sword
/root/Character/Backpack/Dagger
/root/MyGame
/root/Swamp/Alligator
/root/Swamp/Mosquito
/root/Swamp/Goblin
Possible paths are:
GetNode("Sword");
GetNode("Backpack/Dagger");
GetNode("../Swamp/Alligator");
GetNode("/root/MyGame");
Exceptions
- InvalidCastException
The fetched node can't be casted to the given type
T
.
- See Also
GetOwnerOrNull<T>()
The node owner. A node can have any other node as owner (as long as it is a valid parent, grandparent, etc. ascending in the tree). When saving a node (using PackedScene), all the nodes it owns will be saved with it. This allows for the creation of complex SceneTrees, with instancing and subinstancing.
public T GetOwnerOrNull<T>() where T : class
Returns
Type Parameters
T
The type to cast to. Should be a descendant of Node.
- See Also
GetOwner<T>()
The node owner. A node can have any other node as owner (as long as it is a valid parent, grandparent, etc. ascending in the tree). When saving a node (using PackedScene), all the nodes it owns will be saved with it. This allows for the creation of complex SceneTrees, with instancing and subinstancing.
public T GetOwner<T>() where T : class
Returns
- T
The owner Node.
Type Parameters
T
The type to cast to. Should be a descendant of Node.
Exceptions
- InvalidCastException
The fetched node can't be casted to the given type
T
.
- See Also
GetParent()
Returns this node's parent node, or null if the node doesn't have a parent.
public Node GetParent()
Returns
GetParentOrNull<T>()
Returns the parent node of the current node, or a null instance if the node lacks a parent.
public T GetParentOrNull<T>() where T : class
Returns
Type Parameters
T
The type to cast to. Should be a descendant of Node.
- See Also
GetParent<T>()
Returns the parent node of the current node, or a null instance if the node lacks a parent.
public T GetParent<T>() where T : class
Returns
- T
The parent Node.
Type Parameters
T
The type to cast to. Should be a descendant of Node.
Exceptions
- InvalidCastException
The fetched node can't be casted to the given type
T
.
- See Also
GetPath()
Returns the node's absolute path, relative to the Root. If the node is not inside the scene tree, this method fails and returns an empty NodePath.
public NodePath GetPath()
Returns
GetPathTo(Node, bool)
Returns the relative NodePath from this node to the specified node
. Both nodes must be in the same SceneTree or scene hierarchy, otherwise this method fails and returns an empty NodePath.
If useUniquePath
is true, returns the shortest path accounting for this node's unique name (see UniqueNameInOwner).
Note: If you get a relative path which starts from a unique node, the path may be longer than a normal relative path, due to the addition of the unique node's name.
public NodePath GetPathTo(Node node, bool useUniquePath = false)
Parameters
Returns
GetPhysicsProcessDeltaTime()
Returns the time elapsed (in seconds) since the last physics callback. This value is identical to _PhysicsProcess(double)'s delta
parameter, and is often consistent at run-time, unless PhysicsTicksPerSecond is changed. See also NotificationPhysicsProcess.
public double GetPhysicsProcessDeltaTime()
Returns
GetProcessDeltaTime()
Returns the time elapsed (in seconds) since the last process callback. This value is identical to _Process(double)'s delta
parameter, and may vary from frame to frame. See also NotificationProcess.
public double GetProcessDeltaTime()
Returns
GetSceneInstanceLoadPlaceholder()
Returns true if this node is an instance load placeholder. See InstancePlaceholder and SetSceneInstanceLoadPlaceholder(bool).
public bool GetSceneInstanceLoadPlaceholder()
Returns
GetTree()
Returns the SceneTree that contains this node. If this node is not inside the tree, generates an error and returns null. See also IsInsideTree().
public SceneTree GetTree()
Returns
GetTreeString()
Returns the tree as a string. Used mainly for debugging purposes. This version displays the path relative to the current node, and is good for copy/pasting into the GetNode(NodePath) function. It also can be used in game UI/UX.
May print, for example:
TheGame
TheGame/Menu
TheGame/Menu/Label
TheGame/Menu/Camera2D
TheGame/SplashScreen
TheGame/SplashScreen/Camera2D
public string GetTreeString()
Returns
GetTreeStringPretty()
Similar to GetTreeString(), this returns the tree as a string. This version displays a more graphical representation similar to what is displayed in the Scene Dock. It is useful for inspecting larger trees.
May print, for example:
┖╴TheGame
┠╴Menu
┃ ┠╴Label
┃ ┖╴Camera2D
┖╴SplashScreen
┖╴Camera2D
public string GetTreeStringPretty()
Returns
GetViewport()
Returns the node's closest Viewport ancestor, if the node is inside the tree. Otherwise, returns null.
public Viewport GetViewport()
Returns
GetWindow()
Returns the Window that contains this node. If the node is in the main window, this is equivalent to getting the root node (get_tree().get_root()
).
public Window GetWindow()
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
HasNode(NodePath)
Returns true if the path
points to a valid node. See also GetNode(NodePath).
public bool HasNode(NodePath path)
Parameters
path
NodePath
Returns
HasNodeAndResource(NodePath)
Returns true if path
points to a valid node and its subnames point to a valid Resource, e.g. Area2D/CollisionShape2D:shape
. Properties that are not Resource types (such as nodes or other Variant types) are not considered. See also GetNodeAndResource(NodePath).
public bool HasNodeAndResource(NodePath path)
Parameters
path
NodePath
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
IsAncestorOf(Node)
Returns true if the given node
is a direct or indirect child of this node.
public bool IsAncestorOf(Node node)
Parameters
node
Node
Returns
IsDisplayedFolded()
Returns true if the node is folded (collapsed) in the Scene dock. This method is intended to be used in editor plugins and tools. See also SetDisplayFolded(bool).
public bool IsDisplayedFolded()
Returns
IsEditableInstance(Node)
Returns true if node
has editable children enabled relative to this node. This method is intended to be used in editor plugins and tools. See also SetEditableInstance(Node, bool).
public bool IsEditableInstance(Node node)
Parameters
node
Node
Returns
IsGreaterThan(Node)
Returns true if the given node
occurs later in the scene hierarchy than this node. A node occurring later is usually processed last.
public bool IsGreaterThan(Node node)
Parameters
node
Node
Returns
IsInGroup(StringName)
Returns true if this node has been added to the given group
. See AddToGroup(StringName, bool) and RemoveFromGroup(StringName). See also notes in the description, and the SceneTree's group methods.
public bool IsInGroup(StringName group)
Parameters
group
StringName
Returns
IsInsideTree()
public bool IsInsideTree()
Returns
IsMultiplayerAuthority()
Returns true if the local system is the multiplayer authority of this node.
public bool IsMultiplayerAuthority()
Returns
IsNodeReady()
Returns true if the node is ready, i.e. it's inside scene tree and all its children are initialized.
RequestReady() resets it back to false.
public bool IsNodeReady()
Returns
IsPartOfEditedScene()
Returns true if the node is part of the scene currently opened in the editor.
public bool IsPartOfEditedScene()
Returns
IsPhysicsInterpolated()
Returns true if physics interpolation is enabled for this node (see PhysicsInterpolationMode).
Note: Interpolation will only be active if both the flag is set and physics interpolation is enabled within the SceneTree. This can be tested using IsPhysicsInterpolatedAndEnabled().
public bool IsPhysicsInterpolated()
Returns
IsPhysicsInterpolatedAndEnabled()
Returns true if physics interpolation is enabled (see PhysicsInterpolationMode) and enabled in the SceneTree.
This is a convenience version of IsPhysicsInterpolated() that also checks whether physics interpolation is enabled globally.
See PhysicsInterpolation and ProjectSettings.physics/common/physics_interpolation
.
public bool IsPhysicsInterpolatedAndEnabled()
Returns
IsPhysicsProcessing()
Returns true if physics processing is enabled (see SetPhysicsProcess(bool)).
public bool IsPhysicsProcessing()
Returns
IsPhysicsProcessingInternal()
Returns true if internal physics processing is enabled (see SetPhysicsProcessInternal(bool)).
public bool IsPhysicsProcessingInternal()
Returns
IsProcessing()
Returns true if processing is enabled (see SetProcess(bool)).
public bool IsProcessing()
Returns
IsProcessingInput()
Returns true if the node is processing input (see SetProcessInput(bool)).
public bool IsProcessingInput()
Returns
IsProcessingInternal()
Returns true if internal processing is enabled (see SetProcessInternal(bool)).
public bool IsProcessingInternal()
Returns
IsProcessingShortcutInput()
Returns true if the node is processing shortcuts (see SetProcessShortcutInput(bool)).
public bool IsProcessingShortcutInput()
Returns
IsProcessingUnhandledInput()
Returns true if the node is processing unhandled input (see SetProcessUnhandledInput(bool)).
public bool IsProcessingUnhandledInput()
Returns
IsProcessingUnhandledKeyInput()
Returns true if the node is processing unhandled key input (see SetProcessUnhandledKeyInput(bool)).
public bool IsProcessingUnhandledKeyInput()
Returns
MoveChild(Node, int)
Moves childNode
to the given index. A node's index is the order among its siblings. If toIndex
is negative, the index is counted from the end of the list. See also GetChild(int, bool) and GetIndex(bool).
Note: The processing order of several engine callbacks (_Ready(), _Process(double), etc.) and notifications sent through PropagateNotification(int) is affected by tree order. CanvasItem nodes are also rendered in tree order. See also ProcessPriority.
public void MoveChild(Node childNode, int toIndex)
Parameters
NotifyDeferredThreadGroup(int)
Similar to CallDeferredThreadGroup(StringName, params Variant[]), but for notifications.
public void NotifyDeferredThreadGroup(int what)
Parameters
what
int
NotifyThreadSafe(int)
Similar to CallThreadSafe(StringName, params Variant[]), but for notifications.
public void NotifyThreadSafe(int what)
Parameters
what
int
PrintOrphanNodes()
Prints all orphan nodes (nodes outside the SceneTree). Useful for debugging.
Note: This method only works in debug builds. Does nothing in a project exported in release mode.
public static void PrintOrphanNodes()
PrintTree()
Prints the node and its children to the console, recursively. The node does not have to be inside the tree. This method outputs NodePaths relative to this node, and is good for copy/pasting into GetNode(NodePath). See also PrintTreePretty().
May print, for example:
.
Menu
Menu/Label
Menu/Camera2D
SplashScreen
SplashScreen/Camera2D
public void PrintTree()
PrintTreePretty()
Prints the node and its children to the console, recursively. The node does not have to be inside the tree. Similar to PrintTree(), but the graphical representation looks like what is displayed in the editor's Scene dock. It is useful for inspecting larger trees.
May print, for example:
┖╴TheGame
┠╴Menu
┃ ┠╴Label
┃ ┖╴Camera2D
┖╴SplashScreen
┖╴Camera2D
public void PrintTreePretty()
PropagateCall(StringName, Array, bool)
Calls the given method
name, passing args
as arguments, on this node and all of its children, recursively.
If parentFirst
is true, the method is called on this node first, then on all of its children. If false, the children's methods are called first.
public void PropagateCall(StringName method, Array args = null, bool parentFirst = false)
Parameters
method
StringNameargs
ArrayparentFirst
bool
PropagateNotification(int)
Calls Notification(int, bool) with what
on this node and all of its children, recursively.
public void PropagateNotification(int what)
Parameters
what
int
QueueFree()
Queues this node to be deleted at the end of the current frame. When deleted, all of its children are deleted as well, and all references to the node and its children become invalid.
Unlike with Free(), the node is not deleted instantly, and it can still be accessed before deletion. It is also safe to call QueueFree() multiple times. Use IsQueuedForDeletion() to check if the node will be deleted at the end of the frame.
Note: The node will only be freed after all other deferred calls are finished. Using this method is not always the same as calling Free() through CallDeferred(StringName, params Variant[]).
public void QueueFree()
RemoveChild(Node)
Removes a child node
. The node
, along with its children, are not deleted. To delete a node, see QueueFree().
Note: When this node is inside the tree, this method sets the Owner of the removed node
(or its descendants) to null, if their Owner is no longer an ancestor (see IsAncestorOf(Node)).
public void RemoveChild(Node node)
Parameters
node
Node
RemoveFromGroup(StringName)
Removes the node from the given group
. Does nothing if the node is not in the group
. See also notes in the description, and the SceneTree's group methods.
public void RemoveFromGroup(StringName group)
Parameters
group
StringName
Reparent(Node, bool)
Changes the parent of this Node to the newParent
. The node needs to already have a parent. The node's Owner is preserved if its owner is still reachable from the new location (i.e., the node is still a descendant of the new parent after the operation).
If keepGlobalTransform
is true, the node's global transform will be preserved if supported. Node2D, Node3D and Control support this argument (but Control keeps only position).
public void Reparent(Node newParent, bool keepGlobalTransform = true)
Parameters
ReplaceBy(Node, bool)
Replaces this node by the given node
. All children of this node are moved to node
.
If keepGroups
is true, the node
is added to the same groups that the replaced node is in (see AddToGroup(StringName, bool)).
Warning: The replaced node is removed from the tree, but it is not deleted. To prevent memory leaks, store a reference to the node in a variable, or use Free().
public void ReplaceBy(Node node, bool keepGroups = false)
Parameters
RequestReady()
Requests _Ready() to be called again the next time the node enters the tree. Does not immediately call _Ready().
Note: This method only affects the current node. If the node's children also need to request ready, this method needs to be called for each one of them. When the node and its children enter the tree again, the order of _Ready() callbacks will be the same as normal.
public void RequestReady()
ResetPhysicsInterpolation()
When physics interpolation is active, moving a node to a radically different transform (such as placement within a level) can result in a visible glitch as the object is rendered moving from the old to new position over the physics tick.
That glitch can be prevented by calling this method, which temporarily disables interpolation until the physics tick is complete.
The notification NotificationResetPhysicsInterpolation will be received by the node and all children recursively.
Note: This function should be called after moving the node, rather than before.
public void ResetPhysicsInterpolation()
Rpc(StringName, params Variant[])
Sends a remote procedure call request for the given method
to peers on the network (and locally), sending additional arguments to the method called by the RPC. The call request will only be received by nodes with the same NodePath, including the exact same Name. Behavior depends on the RPC configuration for the given method
(see RpcConfig(StringName, Variant) and [annotation @GDScript.@rpc]). By default, methods are not exposed to RPCs.
May return Ok if the call is successful, InvalidParameter if the arguments passed in the method
do not match, Unconfigured if the node's Multiplayer cannot be fetched (such as when the node is not inside the tree), ConnectionError if Multiplayer's connection is not available.
Note: You can only safely use RPCs on clients after you received the ConnectedToServer signal from the MultiplayerApi. You also need to keep track of the connection state, either by the MultiplayerApi signals like ServerDisconnected or by checking (get_multiplayer().peer.get_connection_status() == CONNECTION_CONNECTED
).
public Error Rpc(StringName method, params Variant[] args)
Parameters
method
StringNameargs
Variant[]
Returns
RpcConfig(StringName, Variant)
Changes the RPC configuration for the given method
. config
should either be null to disable the feature (as by default), or a Dictionary containing the following entries:
- rpc_mode
: see MultiplayerApi.RpcMode;
- transfer_mode
: see MultiplayerPeer.TransferModeEnum;
- call_local
: if true, the method will also be called locally;
- channel
: an int representing the channel to send the RPC on.
Note: In GDScript, this method corresponds to the [annotation @GDScript.@rpc] annotation, with various parameters passed (@rpc(any)
, @rpc(authority)
...). See also the high-level multiplayer tutorial.
public void RpcConfig(StringName method, Variant config)
Parameters
method
StringNameconfig
Variant
RpcId(long, StringName, params Variant[])
Sends a Rpc(StringName, params Variant[]) to a specific peer identified by peerId
(see SetTargetPeer(int)).
May return Ok if the call is successful, InvalidParameter if the arguments passed in the method
do not match, Unconfigured if the node's Multiplayer cannot be fetched (such as when the node is not inside the tree), ConnectionError if Multiplayer's connection is not available.
public Error RpcId(long peerId, StringName method, params Variant[] args)
Parameters
peerId
longmethod
StringNameargs
Variant[]
Returns
SetDeferredThreadGroup(StringName, Variant)
Similar to CallDeferredThreadGroup(StringName, params Variant[]), but for setting properties.
public void SetDeferredThreadGroup(StringName property, Variant value)
Parameters
property
StringNamevalue
Variant
SetDisplayFolded(bool)
If set to true, the node appears folded in the Scene dock. As a result, all of its children are hidden. This method is intended to be used in editor plugins and tools, but it also works in release builds. See also IsDisplayedFolded().
public void SetDisplayFolded(bool fold)
Parameters
fold
bool
SetEditableInstance(Node, bool)
Set to true to allow all nodes owned by node
to be available, and editable, in the Scene dock, even if their Owner is not the scene root. This method is intended to be used in editor plugins and tools, but it also works in release builds. See also IsEditableInstance(Node).
public void SetEditableInstance(Node node, bool isEditable)
Parameters
SetMultiplayerAuthority(int, bool)
Sets the node's multiplayer authority to the peer with the given peer id
. The multiplayer authority is the peer that has authority over the node on the network. Defaults to peer ID 1 (the server). Useful in conjunction with RpcConfig(StringName, Variant) and the MultiplayerApi.
If recursive
is true, the given peer is recursively set as the authority for all children of this node.
Warning: This does not automatically replicate the new authority to other peers. It is the developer's responsibility to do so. You may replicate the new authority's information using SpawnFunction, an RPC, or a MultiplayerSynchronizer. Furthermore, the parent's authority does not propagate to newly added children.
public void SetMultiplayerAuthority(int id, bool recursive = true)
Parameters
SetPhysicsProcess(bool)
If set to true, enables physics (fixed framerate) processing. When a node is being processed, it will receive a NotificationPhysicsProcess at a fixed (usually 60 FPS, see PhysicsTicksPerSecond to change) interval (and the _PhysicsProcess(double) callback will be called if it exists).
Note: If _PhysicsProcess(double) is overridden, this will be automatically enabled before _Ready() is called.
public void SetPhysicsProcess(bool enable)
Parameters
enable
bool
SetPhysicsProcessInternal(bool)
If set to true, enables internal physics for this node. Internal physics processing happens in isolation from the normal _PhysicsProcess(double) calls and is used by some nodes internally to guarantee proper functioning even if the node is paused or physics processing is disabled for scripting (SetPhysicsProcess(bool)).
Warning: Built-in nodes rely on internal processing for their internal logic. Disabling it is unsafe and may lead to unexpected behavior. Use this method if you know what you are doing.
public void SetPhysicsProcessInternal(bool enable)
Parameters
enable
bool
SetProcess(bool)
If set to true, enables processing. When a node is being processed, it will receive a NotificationProcess on every drawn frame (and the _Process(double) callback will be called if it exists).
Note: If _Process(double) is overridden, this will be automatically enabled before _Ready() is called.
Note: This method only affects the _Process(double) callback, i.e. it has no effect on other callbacks like _PhysicsProcess(double). If you want to disable all processing for the node, set ProcessMode to Disabled.
public void SetProcess(bool enable)
Parameters
enable
bool
SetProcessInput(bool)
If set to true, enables input processing.
Note: If _Input(InputEvent) is overridden, this will be automatically enabled before _Ready() is called. Input processing is also already enabled for GUI controls, such as Button and TextEdit.
public void SetProcessInput(bool enable)
Parameters
enable
bool
SetProcessInternal(bool)
If set to true, enables internal processing for this node. Internal processing happens in isolation from the normal _Process(double) calls and is used by some nodes internally to guarantee proper functioning even if the node is paused or processing is disabled for scripting (SetProcess(bool)).
Warning: Built-in nodes rely on internal processing for their internal logic. Disabling it is unsafe and may lead to unexpected behavior. Use this method if you know what you are doing.
public void SetProcessInternal(bool enable)
Parameters
enable
bool
SetProcessShortcutInput(bool)
If set to true, enables shortcut processing for this node.
Note: If _ShortcutInput(InputEvent) is overridden, this will be automatically enabled before _Ready() is called.
public void SetProcessShortcutInput(bool enable)
Parameters
enable
bool
SetProcessUnhandledInput(bool)
If set to true, enables unhandled input processing. It enables the node to receive all input that was not previously handled (usually by a Control).
Note: If _UnhandledInput(InputEvent) is overridden, this will be automatically enabled before _Ready() is called. Unhandled input processing is also already enabled for GUI controls, such as Button and TextEdit.
public void SetProcessUnhandledInput(bool enable)
Parameters
enable
bool
SetProcessUnhandledKeyInput(bool)
If set to true, enables unhandled key input processing.
Note: If _UnhandledKeyInput(InputEvent) is overridden, this will be automatically enabled before _Ready() is called.
public void SetProcessUnhandledKeyInput(bool enable)
Parameters
enable
bool
SetSceneInstanceLoadPlaceholder(bool)
If set to true, the node becomes a InstancePlaceholder when packed and instantiated from a PackedScene. See also GetSceneInstanceLoadPlaceholder().
public void SetSceneInstanceLoadPlaceholder(bool loadPlaceholder)
Parameters
loadPlaceholder
bool
SetThreadSafe(StringName, Variant)
Similar to CallThreadSafe(StringName, params Variant[]), but for setting properties.
public void SetThreadSafe(StringName property, Variant value)
Parameters
property
StringNamevalue
Variant
UpdateConfigurationWarnings()
Refreshes the warnings displayed for this node in the Scene dock. Use _GetConfigurationWarnings() to customize the warning messages to display.
public void UpdateConfigurationWarnings()
_EnterTree()
Called when the node enters the SceneTree (e.g. upon instantiating, scene changing, or after calling AddChild(Node, bool, InternalMode) in a script). If the node has children, its _EnterTree() callback will be called first, and then that of the children.
Corresponds to the NotificationEnterTree notification in _Notification(int).
public virtual void _EnterTree()
_ExitTree()
Called when the node is about to leave the SceneTree (e.g. upon freeing, scene changing, or after calling RemoveChild(Node) in a script). If the node has children, its _ExitTree() callback will be called last, after all its children have left the tree.
Corresponds to the NotificationExitTree notification in _Notification(int) and signal TreeExiting. To get notified when the node has already left the active tree, connect to the TreeExited.
public virtual void _ExitTree()
_GetConfigurationWarnings()
The elements in the array returned from this method are displayed as warnings in the Scene dock if the script that overrides it is a tool
script.
Returning an empty array produces no warnings.
Call UpdateConfigurationWarnings() when the warnings need to be updated for this node.
@export var energy = 0:
set(value):
energy = value
update_configuration_warnings()
func _get_configuration_warnings():
if energy < 0:
return ["Energy must be 0 or greater."]
else:
return []
public virtual string[] _GetConfigurationWarnings()
Returns
- string[]
_Input(InputEvent)
Called when there is an input event. The input event propagates up through the node tree until a node consumes it.
It is only called if input processing is enabled, which is done automatically if this method is overridden, and can be toggled with SetProcessInput(bool).
To consume the input event and stop it propagating further to other nodes, SetInputAsHandled() can be called.
For gameplay input, _UnhandledInput(InputEvent) and _UnhandledKeyInput(InputEvent) are usually a better fit as they allow the GUI to intercept the events first.
Note: This method is only called if the node is present in the scene tree (i.e. if it's not an orphan).
public virtual void _Input(InputEvent @event)
Parameters
event
InputEvent
_PhysicsProcess(double)
Called during the physics processing step of the main loop. Physics processing means that the frame rate is synced to the physics, i.e. the delta
variable should be constant. delta
is in seconds.
It is only called if physics processing is enabled, which is done automatically if this method is overridden, and can be toggled with SetPhysicsProcess(bool).
Corresponds to the NotificationPhysicsProcess notification in _Notification(int).
Note: This method is only called if the node is present in the scene tree (i.e. if it's not an orphan).
public virtual void _PhysicsProcess(double delta)
Parameters
delta
double
_Process(double)
Called during the processing step of the main loop. Processing happens at every frame and as fast as possible, so the delta
time since the previous frame is not constant. delta
is in seconds.
It is only called if processing is enabled, which is done automatically if this method is overridden, and can be toggled with SetProcess(bool).
Corresponds to the NotificationProcess notification in _Notification(int).
Note: This method is only called if the node is present in the scene tree (i.e. if it's not an orphan).
public virtual void _Process(double delta)
Parameters
delta
double
_Ready()
Called when the node is "ready", i.e. when both the node and its children have entered the scene tree. If the node has children, their _Ready() callbacks get triggered first, and the parent node will receive the ready notification afterwards.
Corresponds to the NotificationReady notification in _Notification(int). See also the @onready
annotation for variables.
Usually used for initialization. For even earlier initialization, GodotObject() may be used. See also _EnterTree().
Note: This method may be called only once for each node. After removing a node from the scene tree and adding it again, _Ready() will not be called a second time. This can be bypassed by requesting another call with RequestReady(), which may be called anywhere before adding the node again.
public virtual void _Ready()
_ShortcutInput(InputEvent)
Called when an InputEventKey, InputEventShortcut, or InputEventJoypadButton hasn't been consumed by _Input(InputEvent) or any GUI Control item. It is called before _UnhandledKeyInput(InputEvent) and _UnhandledInput(InputEvent). The input event propagates up through the node tree until a node consumes it.
It is only called if shortcut processing is enabled, which is done automatically if this method is overridden, and can be toggled with SetProcessShortcutInput(bool).
To consume the input event and stop it propagating further to other nodes, SetInputAsHandled() can be called.
This method can be used to handle shortcuts. For generic GUI events, use _Input(InputEvent) instead. Gameplay events should usually be handled with either _UnhandledInput(InputEvent) or _UnhandledKeyInput(InputEvent).
Note: This method is only called if the node is present in the scene tree (i.e. if it's not orphan).
public virtual void _ShortcutInput(InputEvent @event)
Parameters
event
InputEvent
_UnhandledInput(InputEvent)
Called when an InputEvent hasn't been consumed by _Input(InputEvent) or any GUI Control item. It is called after _ShortcutInput(InputEvent) and after _UnhandledKeyInput(InputEvent). The input event propagates up through the node tree until a node consumes it.
It is only called if unhandled input processing is enabled, which is done automatically if this method is overridden, and can be toggled with SetProcessUnhandledInput(bool).
To consume the input event and stop it propagating further to other nodes, SetInputAsHandled() can be called.
For gameplay input, this method is usually a better fit than _Input(InputEvent), as GUI events need a higher priority. For keyboard shortcuts, consider using _ShortcutInput(InputEvent) instead, as it is called before this method. Finally, to handle keyboard events, consider using _UnhandledKeyInput(InputEvent) for performance reasons.
Note: This method is only called if the node is present in the scene tree (i.e. if it's not an orphan).
public virtual void _UnhandledInput(InputEvent @event)
Parameters
event
InputEvent
_UnhandledKeyInput(InputEvent)
Called when an InputEventKey hasn't been consumed by _Input(InputEvent) or any GUI Control item. It is called after _ShortcutInput(InputEvent) but before _UnhandledInput(InputEvent). The input event propagates up through the node tree until a node consumes it.
It is only called if unhandled key input processing is enabled, which is done automatically if this method is overridden, and can be toggled with SetProcessUnhandledKeyInput(bool).
To consume the input event and stop it propagating further to other nodes, SetInputAsHandled() can be called.
This method can be used to handle Unicode character input with Alt, Alt + Ctrl, and Alt + Shift modifiers, after shortcuts were handled.
For gameplay input, this and _UnhandledInput(InputEvent) are usually a better fit than _Input(InputEvent), as GUI events should be handled first. This method also performs better than _UnhandledInput(InputEvent), since unrelated events such as InputEventMouseMotion are automatically filtered. For shortcuts, consider using _ShortcutInput(InputEvent) instead.
Note: This method is only called if the node is present in the scene tree (i.e. if it's not an orphan).
public virtual void _UnhandledKeyInput(InputEvent @event)
Parameters
event
InputEvent
Events
ChildEnteredTree
Emitted when the child node
enters the SceneTree, usually because this node entered the tree (see TreeEntered), or AddChild(Node, bool, InternalMode) has been called.
This signal is emitted after the child node's own NotificationEnterTree and TreeEntered.
public event Node.ChildEnteredTreeEventHandler ChildEnteredTree
Event Type
ChildExitingTree
Emitted when the child node
is about to exit the SceneTree, usually because this node is exiting the tree (see TreeExiting), or because the child node
is being removed or freed.
When this signal is received, the child node
is still accessible inside the tree. This signal is emitted after the child node's own TreeExiting and NotificationExitTree.
public event Node.ChildExitingTreeEventHandler ChildExitingTree
Event Type
ChildOrderChanged
Emitted when the list of children is changed. This happens when child nodes are added, moved or removed.
public event Action ChildOrderChanged
Event Type
EditorDescriptionChanged
Emitted when the node's editor description field changed.
public event Node.EditorDescriptionChangedEventHandler EditorDescriptionChanged
Event Type
Ready
Emitted when the node is considered ready, after _Ready() is called.
public event Action Ready
Event Type
Renamed
Emitted when the node's Name is changed, if the node is inside the tree.
public event Action Renamed
Event Type
ReplacingBy
Emitted when this node is being replaced by the node
, see ReplaceBy(Node, bool).
This signal is emitted afternode
has been added as a child of the original parent node, but before all original child nodes have been reparented to node
.
public event Node.ReplacingByEventHandler ReplacingBy
Event Type
TreeEntered
Emitted when the node enters the tree.
This signal is emitted after the related NotificationEnterTree notification.
public event Action TreeEntered
Event Type
TreeExited
Emitted after the node exits the tree and is no longer active.
This signal is emitted after the related NotificationExitTree notification.
public event Action TreeExited
Event Type
TreeExiting
Emitted when the node is just about to exit the tree. The node is still valid. As such, this is the right place for de-initialization (or a "destructor", if you will).
This signal is emitted after the node's _ExitTree(), and before the related NotificationExitTree.
public event Action TreeExiting