class RayCast2D
package godot
extends Node2D › CanvasItem › Node › Object
@:nativeGen@:build(godot.Godot.buildUserClass())@:autoBuild(godot.Godot.buildUserClass())@:build(godot.Godot.buildUserClass())@:autoBuild(godot.Godot.buildUserClass())@:build(godot.Godot.buildUserClass())@:autoBuild(godot.Godot.buildUserClass())@:build(godot.Godot.buildUserClass())@:autoBuild(godot.Godot.buildUserClass())@:libType@:csNative@:native("Godot.RayCast2D")@:autoBuild(godot.Godot.buildUserClass())A RayCast represents a line from its origin to its destination position, cast_to
. It is used to query the 2D space in order to find the closest object along the path of the ray.
RayCast2D can ignore some objects by adding them to the exception list via add_exception
, by setting proper filtering with collision layers, or by filtering object types with type masks.
RayCast2D can be configured to report collisions with godot.Area2D
s (godot.RayCast2D.collideWithAreas
) and/or godot.PhysicsBody2D
s (godot.RayCast2D.collideWithBodies
).
Only enabled raycasts will be able to query the space and report collisions.
RayCast2D calculates intersection every physics frame (see godot.Node
), and the result is cached so it can be used later until the next frame. If multiple queries are required between physics frames (or during the same frame) use godot.RayCast2D.forceRaycastUpdate
after adjusting the raycast.
Constructor
Variables
@:native("CollideWithAreas")collideWithAreas:Bool
If true
, collision with godot.Area2D
s will be reported.
@:native("CollideWithBodies")collideWithBodies:Bool
If true
, collision with godot.PhysicsBody2D
s will be reported.
@:native("CollisionMask")collisionMask:UInt
The ray's collision mask. Only objects in at least one collision layer enabled in the mask will be detected. See [https://docs.godotengine.org/en/3.4/tutorials/physics/physics_introduction.html#collision-layers-and-masks](Collision layers and masks) in the documentation for more information.
@:native("ExcludeParent")excludeParent:Bool
If true
, the parent node will be excluded from collision detection.
Methods
@:native("AddException")addException(node:Object):Void
Adds a collision exception so the ray does not report collisions with the specified node.
@:native("AddExceptionRid")addExceptionRid(rid:RID):Void
Adds a collision exception so the ray does not report collisions with the specified godot.RID
.
@:native("ForceRaycastUpdate")forceRaycastUpdate():Void
Updates the collision information for the ray. Use this method to update the collision information immediately instead of waiting for the next _physics_process
call, for example if the ray or its parent has changed state.
Note: enabled
is not required for this to work.
@:native("GetCollider")getCollider():Object
Returns the first object that the ray intersects, or null
if no object is intersecting the ray (i.e. godot.RayCast2D.isColliding
returns false
).
@:native("GetColliderShape")getColliderShape():Int
Returns the shape ID of the first object that the ray intersects, or 0
if no object is intersecting the ray (i.e. godot.RayCast2D.isColliding
returns false
).
@:native("GetCollisionMaskBit")getCollisionMaskBit(bit:Int):Bool
Returns an individual bit on the collision mask.
@:native("GetCollisionNormal")getCollisionNormal():Vector2
Returns the normal of the intersecting object's shape at the collision point.
@:native("GetCollisionPoint")getCollisionPoint():Vector2
Returns the collision point at which the ray intersects the closest object.
Note: This point is in the global coordinate system.
@:native("IsColliding")isColliding():Bool
Returns whether any object is intersecting with the ray's vector (considering the vector length).
@:native("RemoveException")removeException(node:Object):Void
Removes a collision exception so the ray does report collisions with the specified node.
@:native("RemoveExceptionRid")removeExceptionRid(rid:RID):Void
Removes a collision exception so the ray does report collisions with the specified godot.RID
.
@:native("SetCollisionMaskBit")setCollisionMaskBit(bit:Int, value:Bool):Void
Sets or clears individual bits on the collision mask. This makes selecting the areas scanned easier.
Inherited Variables
Defined by Node2D
@:native("RotationDegrees")rotationDegrees:Single
Rotation in degrees, relative to the node's parent.
@:native("ZAsRelative")zAsRelative:Bool
If true
, the node's Z index is relative to its parent's Z index. If this node's Z index is 2 and its parent's effective Z index is 3, then this node's effective Z index will be 2 + 3 = 5.
@:native("ZIndex")zIndex:Int
Z index. Controls the order in which the nodes render. A node with a higher Z index will display in front of others. Must be between godot.VisualServer.canvasItemZMin
and godot.VisualServer.canvasItemZMax
(inclusive).
Defined by CanvasItem
@:native("LightMask")lightMask:Int
The rendering layers in which this godot.CanvasItem
responds to godot.Light2D
nodes.
@:native("SelfModulate")selfModulate:Color
The color applied to textures on this godot.CanvasItem
. This is not inherited by children godot.CanvasItem
s.
@:native("UseParentMaterial")useParentMaterial:Bool
If true
, the parent godot.CanvasItem
's godot.CanvasItem.material
property is used as this one's material.
@:native("Visible")visible:Bool
If true
, this godot.CanvasItem
is drawn. The node is only visible if all of its antecedents are visible as well (in other words, godot.CanvasItem.isVisibleInTree
must return true
).
Note: For controls that inherit godot.Popup
, the correct way to make them visible is to call one of the multiple popup*()
functions instead.
Defined by Node
@:native("CustomMultiplayer")customMultiplayer:MultiplayerAPI
The override to the default godot.MultiplayerAPI
. Set to null
to use the default godot.SceneTree
one.
@:native("Filename")filename:String
If a scene is instantiated from a file, its topmost node contains the absolute file path from which it was loaded in godot.Node.filename
(e.g. res://levels/1.tscn
). Otherwise, godot.Node.filename
is set to an empty string.
@:native("Multiplayer")read onlymultiplayer:MultiplayerAPI
The godot.MultiplayerAPI
instance associated with this node. Either the godot.Node.customMultiplayer
, or the default SceneTree one (if inside tree).
@:native("Name")name:String
The name of the node. This name is unique among the siblings (other child nodes from the same parent). When set to an existing name, the node will be automatically renamed.
Note: Auto-generated names might include the @
character, which is reserved for unique names when using godot.Node.addChild
. When setting the name manually, any @
will be removed.
@:native("Owner")owner:Node
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 godot.PackedScene
), all the nodes it owns will be saved with it. This allows for the creation of complex godot.SceneTree
s, with instancing and subinstancing.
Note: If you want a child to be persisted to a godot.PackedScene
, you must set godot.Node.owner
in addition to calling godot.Node.addChild
. This is typically relevant for [https://docs.godotengine.org/en/3.4/tutorials/misc/running_code_in_the_editor.html](tool scripts) and [https://docs.godotengine.org/en/3.4/tutorials/plugins/editor/index.html](editor plugins). If godot.Node.addChild
is called without setting godot.Node.owner
, the newly added godot.Node
will not be visible in the scene tree, though it will be visible in the 2D/3D view.
@:native("PauseMode")pauseMode:Node_PauseModeEnum
Pause mode. How the node will behave if the godot.SceneTree
is paused.
@:native("ProcessPriority")processPriority:Int
The node's priority in the execution order of the enabled processing callbacks (i.e. godot.Node.notificationProcess
, godot.Node.notificationPhysicsProcess
and their internal counterparts). Nodes whose process priority value is lower will have their processing callbacks executed first.
Defined by Object
@:native("DynamicObject")read onlydynamicObject:Dynamic
Gets a new godot.DynamicGodotObject
associated with this instance.
@:native("NativeInstance")read onlynativeInstance:IntPtr
The pointer to the native instance of this godot.Object
.
Inherited Methods
Defined by Node2D
@:native("ApplyScale")applyScale(ratio:Vector2):Void
Multiplies the current scale by the ratio
vector.
@:native("GetAngleTo")getAngleTo(point:Vector2):Single
Returns the angle between the node and the point
in radians.
[https://raw.githubusercontent.com/godotengine/godot-docs/master/img/node2d_get_angle_to.png](Illustration of the returned angle.)
@:native("GetRelativeTransformToParent")getRelativeTransformToParent(parent:Node):Transform2D
Returns the godot.Transform2D
relative to this node's parent.
@:native("GlobalTranslate")globalTranslate(offset:Vector2):Void
Adds the offset
vector to the node's global position.
@:native("LookAt")lookAt(point:Vector2):Void
Rotates the node so it points towards the point
, which is expected to use global coordinates.
@:native("MoveLocalX")moveLocalX(delta:Single, ?scaled:Bool):Void
Applies a local translation on the node's X axis based on the godot.Node._Process
's delta
. If scaled
is false
, normalizes the movement.
@:native("MoveLocalY")moveLocalY(delta:Single, ?scaled:Bool):Void
Applies a local translation on the node's Y axis based on the godot.Node._Process
's delta
. If scaled
is false
, normalizes the movement.
@:native("Rotate")rotate(radians:Single):Void
Applies a rotation to the node, in radians, starting from its current rotation.
@:native("ToGlobal")toGlobal(localPoint:Vector2):Vector2
Transforms the provided local position into a position in global coordinate space. The input is expected to be local relative to the godot.Node2D
it is called on. e.g. Applying this method to the positions of child nodes will correctly transform their positions into the global coordinate space, but applying it to a node's own position will give an incorrect result, as it will incorporate the node's own transformation into its global position.
@:native("ToLocal")toLocal(globalPoint:Vector2):Vector2
Transforms the provided global position into a position in local coordinate space. The output will be local relative to the godot.Node2D
it is called on. e.g. It is appropriate for determining the positions of child nodes, but it is not appropriate for determining its own position relative to its parent.
Defined by CanvasItem
@:native("_Draw")_Draw():Void
Overridable function called by the engine (if defined) to draw the canvas item.
@:native("DrawArc")drawArc(center:Vector2, radius:Single, startAngle:Single, endAngle:Single, pointCount:Int, color:Color, ?width:Single, ?antialiased:Bool):Void
Draws a unfilled arc between the given angles. The larger the value of point_count
, the smoother the curve. See also godot.CanvasItem.drawCircle
.
Note: Line drawing is not accelerated by batching if antialiased
is true
.
Note: Due to how it works, built-in antialiasing will not look correct for translucent lines and may not work on certain platforms. As a workaround, install the [https://github.com/godot-extended-libraries/godot-antialiased-line2d](Antialiased Line2D) add-on then create an AntialiasedRegularPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing. 2D batching is also still supported with those antialiased lines.
@:native("DrawChar")drawChar(font:Font, position:Vector2, char:String, next:String, ?modulate:Color):Single
Draws a string character using a custom font. Returns the advance, depending on the character width and kerning with an optional next character.
Parameters:
modulate | If the parameter is null, then the default value is new Color(1, 1, 1, 1) |
---|
@:native("DrawCircle")drawCircle(position:Vector2, radius:Single, color:Color):Void
Draws a colored, filled circle. See also godot.CanvasItem.drawArc
, godot.CanvasItem.drawPolyline
and godot.CanvasItem.drawPolygon
.
Note: Built-in antialiasing is not provided for godot.CanvasItem.drawCircle
. As a workaround, install the [https://github.com/godot-extended-libraries/godot-antialiased-line2d](Antialiased Line2D) add-on then create an AntialiasedRegularPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.
@:native("DrawColoredPolygon")drawColoredPolygon(points:Array<Vector2>, color:Color, ?uvs:Array<Vector2>, ?texture:Texture, ?normalMap:Texture, ?antialiased:Bool):Void
Draws a colored polygon of any amount of points, convex or concave. Unlike godot.CanvasItem.drawPolygon
, a single color must be specified for the whole polygon.
Note: Due to how it works, built-in antialiasing will not look correct for translucent polygons and may not work on certain platforms. As a workaround, install the [https://github.com/godot-extended-libraries/godot-antialiased-line2d](Antialiased Line2D) add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.
Parameters:
uvs | If the parameter is null, then the default value is Array.Empty<Vector2>() |
---|
@:native("DrawLine")drawLine(from:Vector2, to:Vector2, color:Color, ?width:Single, ?antialiased:Bool):Void
Draws a line from a 2D point to another, with a given color and width. It can be optionally antialiased. See also godot.CanvasItem.drawMultiline
and godot.CanvasItem.drawPolyline
.
Note: Line drawing is not accelerated by batching if antialiased
is true
.
Note: Due to how it works, built-in antialiasing will not look correct for translucent lines and may not work on certain platforms. As a workaround, install the [https://github.com/godot-extended-libraries/godot-antialiased-line2d](Antialiased Line2D) add-on then create an AntialiasedLine2D node. That node relies on a texture with custom mipmaps to perform antialiasing. 2D batching is also still supported with those antialiased lines.
@:native("DrawMesh")drawMesh(mesh:Mesh, texture:Texture, ?normalMap:Texture, ?transform:Transform2D, ?modulate:Color):Void
Draws a godot.Mesh
in 2D, using the provided texture. See godot.MeshInstance2D
for related documentation.
Parameters:
transform | If the parameter is null, then the default value is Transform2D.Identity |
---|---|
modulate | If the parameter is null, then the default value is new Color(1, 1, 1, 1) |
@:native("DrawMultiline")drawMultiline(points:Array<Vector2>, color:Color, ?width:Single, ?antialiased:Bool):Void
Draws multiple disconnected lines with a uniform color
. When drawing large amounts of lines, this is faster than using individual godot.CanvasItem.drawLine
calls. To draw interconnected lines, use godot.CanvasItem.drawPolyline
instead.
Note: width
and antialiased
are currently not implemented and have no effect. As a workaround, install the [https://github.com/godot-extended-libraries/godot-antialiased-line2d](Antialiased Line2D) add-on then create an AntialiasedLine2D node. That node relies on a texture with custom mipmaps to perform antialiasing. 2D batching is also still supported with those antialiased lines.
@:native("DrawMultilineColors")drawMultilineColors(points:Array<Vector2>, colors:Array<Color>, ?width:Single, ?antialiased:Bool):Void
Draws multiple disconnected lines with a uniform width
and segment-by-segment coloring. Colors assigned to line segments match by index between points
and colors
. When drawing large amounts of lines, this is faster than using individual godot.CanvasItem.drawLine
calls. To draw interconnected lines, use godot.CanvasItem.drawPolylineColors
instead.
Note: width
and antialiased
are currently not implemented and have no effect. As a workaround, install the [https://github.com/godot-extended-libraries/godot-antialiased-line2d](Antialiased Line2D) add-on then create an AntialiasedLine2D node. That node relies on a texture with custom mipmaps to perform antialiasing. 2D batching is also still supported with those antialiased lines.
@:native("DrawMultimesh")drawMultimesh(multimesh:MultiMesh, texture:Texture, ?normalMap:Texture):Void
Draws a godot.MultiMesh
in 2D with the provided texture. See godot.MultiMeshInstance2D
for related documentation.
@:native("DrawPolygon")drawPolygon(points:Array<Vector2>, colors:Array<Color>, ?uvs:Array<Vector2>, ?texture:Texture, ?normalMap:Texture, ?antialiased:Bool):Void
Draws a solid polygon of any amount of points, convex or concave. Unlike godot.CanvasItem.drawColoredPolygon
, each point's color can be changed individually. See also godot.CanvasItem.drawPolyline
and godot.CanvasItem.drawPolylineColors
.
Note: Due to how it works, built-in antialiasing will not look correct for translucent polygons and may not work on certain platforms. As a workaround, install the [https://github.com/godot-extended-libraries/godot-antialiased-line2d](Antialiased Line2D) add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.
Parameters:
uvs | If the parameter is null, then the default value is Array.Empty<Vector2>() |
---|
@:native("DrawPolyline")drawPolyline(points:Array<Vector2>, color:Color, ?width:Single, ?antialiased:Bool):Void
Draws interconnected line segments with a uniform color
and width
and optional antialiasing. When drawing large amounts of lines, this is faster than using individual godot.CanvasItem.drawLine
calls. To draw disconnected lines, use godot.CanvasItem.drawMultiline
instead. See also godot.CanvasItem.drawPolygon
.
Note: Due to how it works, built-in antialiasing will not look correct for translucent polygons and may not work on certain platforms. As a workaround, install the [https://github.com/godot-extended-libraries/godot-antialiased-line2d](Antialiased Line2D) add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.
@:native("DrawPolylineColors")drawPolylineColors(points:Array<Vector2>, colors:Array<Color>, ?width:Single, ?antialiased:Bool):Void
Draws interconnected line segments with a uniform width
and segment-by-segment coloring, and optional antialiasing. Colors assigned to line segments match by index between points
and colors
. When drawing large amounts of lines, this is faster than using individual godot.CanvasItem.drawLine
calls. To draw disconnected lines, use godot.CanvasItem.drawMultilineColors
instead. See also godot.CanvasItem.drawPolygon
.
Note: Due to how it works, built-in antialiasing will not look correct for translucent polygons and may not work on certain platforms. As a workaround, install the [https://github.com/godot-extended-libraries/godot-antialiased-line2d](Antialiased Line2D) add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.
@:native("DrawPrimitive")drawPrimitive(points:Array<Vector2>, colors:Array<Color>, uvs:Array<Vector2>, ?texture:Texture, ?width:Single, ?normalMap:Texture):Void
Draws a custom primitive. 1 point for a point, 2 points for a line, 3 points for a triangle, and 4 points for a quad. If 0 points or more than 4 points are specified, nothing will be drawn and an error message will be printed. See also godot.CanvasItem.drawLine
, godot.CanvasItem.drawPolyline
, godot.CanvasItem.drawPolygon
, and godot.CanvasItem.drawRect
.
@:native("DrawRect")drawRect(rect:Rect2, color:Color, ?filled:Bool, ?width:Single, ?antialiased:Bool):Void
Draws a rectangle. If filled
is true
, the rectangle will be filled with the color
specified. If filled
is false
, the rectangle will be drawn as a stroke with the color
and width
specified. If antialiased
is true
, the lines will attempt to perform antialiasing using OpenGL line smoothing.
Note: width
and antialiased
are only effective if filled
is false
.
Note: Due to how it works, built-in antialiasing will not look correct for translucent polygons and may not work on certain platforms. As a workaround, install the [https://github.com/godot-extended-libraries/godot-antialiased-line2d](Antialiased Line2D) add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.
@:native("DrawSetTransform")drawSetTransform(position:Vector2, rotation:Single, scale:Vector2):Void
Sets a custom transform for drawing via components. Anything drawn afterwards will be transformed by this.
@:native("DrawSetTransformMatrix")drawSetTransformMatrix(xform:Transform2D):Void
Sets a custom transform for drawing via matrix. Anything drawn afterwards will be transformed by this.
@:native("DrawString")drawString(font:Font, position:Vector2, text:String, ?modulate:Color, ?clipW:Int):Void
Draws text
using the specified font
at the position
(bottom-left corner using the baseline of the font). The text will have its color multiplied by modulate
. If clip_w
is greater than or equal to 0, the text will be clipped if it exceeds the specified width.
Example using the default project font:
# If using this method in a script that redraws constantly, move the
# `default_font` declaration to a member variable assigned in `_ready()`
# so the Control is only created once.
var default_font = Control.new().get_font("font")
draw_string(default_font, Vector2(64, 64), "Hello world")
See also godot.Font.draw
.
Parameters:
modulate | If the parameter is null, then the default value is new Color(1, 1, 1, 1) |
---|
@:native("DrawTexture")drawTexture(texture:Texture, position:Vector2, ?modulate:Color, ?normalMap:Texture):Void
Draws a texture at a given position.
Parameters:
modulate | If the parameter is null, then the default value is new Color(1, 1, 1, 1) |
---|
@:native("DrawTextureRect")drawTextureRect(texture:Texture, rect:Rect2, tile:Bool, ?modulate:Color, ?transpose:Bool, ?normalMap:Texture):Void
Draws a textured rectangle at a given position, optionally modulated by a color. If transpose
is true
, the texture will have its X and Y coordinates swapped.
Parameters:
modulate | If the parameter is null, then the default value is new Color(1, 1, 1, 1) |
---|
@:native("DrawTextureRectRegion")drawTextureRectRegion(texture:Texture, rect:Rect2, srcRect:Rect2, ?modulate:Color, ?transpose:Bool, ?normalMap:Texture, ?clipUv:Bool):Void
Draws a textured rectangle region at a given position, optionally modulated by a color. If transpose
is true
, the texture will have its X and Y coordinates swapped.
Parameters:
modulate | If the parameter is null, then the default value is new Color(1, 1, 1, 1) |
---|
@:native("ForceUpdateTransform")forceUpdateTransform():Void
Forces the transform to update. Transform changes in physics are not instant for performance reasons. Transforms are accumulated and then set. Use this if you need an up-to-date transform when doing physics operations.
@:native("GetCanvas")getCanvas():RID
Returns the godot.RID
of the godot.World2D
canvas where this item is in.
@:native("GetCanvasItem")getCanvasItem():RID
Returns the canvas item RID used by godot.VisualServer
for this item.
@:native("GetCanvasTransform")getCanvasTransform():Transform2D
Returns the transform matrix of this item's canvas.
@:native("GetGlobalMousePosition")getGlobalMousePosition():Vector2
Returns the global position of the mouse.
@:native("GetGlobalTransform")getGlobalTransform():Transform2D
Returns the global transform matrix of this item.
@:native("GetGlobalTransformWithCanvas")getGlobalTransformWithCanvas():Transform2D
Returns the global transform matrix of this item in relation to the canvas.
@:native("GetLocalMousePosition")getLocalMousePosition():Vector2
Returns the mouse position relative to this item's position.
@:native("GetViewportRect")getViewportRect():Rect2
Returns the viewport's boundaries as a godot.Rect2
.
@:native("GetViewportTransform")getViewportTransform():Transform2D
Returns this item's transform in relation to the viewport.
@:native("Hide")hide():Void
Hide the godot.CanvasItem
if it's currently visible. This is equivalent to setting godot.CanvasItem.visible
to false
.
@:native("IsLocalTransformNotificationEnabled")isLocalTransformNotificationEnabled():Bool
Returns true
if local transform notifications are communicated to children.
@:native("IsSetAsToplevel")isSetAsToplevel():Bool
Returns true
if the node is set as top-level. See godot.CanvasItem.setAsToplevel
.
@:native("IsTransformNotificationEnabled")isTransformNotificationEnabled():Bool
Returns true
if global transform notifications are communicated to children.
@:native("IsVisibleInTree")isVisibleInTree():Bool
Returns true
if the node is present in the godot.SceneTree
, its godot.CanvasItem.visible
property is true
and all its antecedents are also visible. If any antecedent is hidden, this node will not be visible in the scene tree.
@:native("MakeCanvasPositionLocal")makeCanvasPositionLocal(screenPoint:Vector2):Vector2
Assigns screen_point
as this node's new local transform.
@:native("MakeInputLocal")makeInputLocal(event:InputEvent):InputEvent
Transformations issued by event
's inputs are applied in local space instead of global space.
@:native("SetAsToplevel")setAsToplevel(enable:Bool):Void
If enable
is true
, this godot.CanvasItem
will not inherit its transform from parent godot.CanvasItem
s. Its draw order will also be changed to make it draw on top of other godot.CanvasItem
s that are not set as top-level. The godot.CanvasItem
will effectively act as if it was placed as a child of a bare godot.Node
. See also godot.CanvasItem.isSetAsToplevel
.
@:native("SetNotifyLocalTransform")setNotifyLocalTransform(enable:Bool):Void
If enable
is true
, children will be updated with local transform data.
@:native("SetNotifyTransform")setNotifyTransform(enable:Bool):Void
If enable
is true
, children will be updated with global transform data.
@:native("Show")show():Void
Show the godot.CanvasItem
if it's currently hidden. This is equivalent to setting godot.CanvasItem.visible
to true
. For controls that inherit godot.Popup
, the correct way to make them visible is to call one of the multiple popup*()
functions instead.
@:native("Update")update():Void
Queue the godot.CanvasItem
for update. godot.CanvasItem.notificationDraw
will be called on idle time to request redraw.
Defined by Node
@:native("_EnterTree")_EnterTree():Void
Called when the node enters the godot.SceneTree
(e.g. upon instancing, scene changing, or after calling godot.Node.addChild
in a script). If the node has children, its godot.Node._EnterTree
callback will be called first, and then that of the children.
Corresponds to the godot.Node.notificationEnterTree
notification in godot.Object._Notification
.
@:native("_ExitTree")_ExitTree():Void
Called when the node is about to leave the godot.SceneTree
(e.g. upon freeing, scene changing, or after calling godot.Node.removeChild
in a script). If the node has children, its godot.Node._ExitTree
callback will be called last, after all its children have left the tree.
Corresponds to the godot.Node.notificationExitTree
notification in godot.Object._Notification
and signal tree_exiting
. To get notified when the node has already left the active tree, connect to the tree_exited
.
@:native("_GetConfigurationWarning")_GetConfigurationWarning():String
The string returned from this method is displayed as a warning in the Scene Dock if the script that overrides it is a tool
script.
Returning an empty string produces no warning.
Call godot.Node.updateConfigurationWarning
when the warning needs to be updated for this node.
@:native("_Input")_Input(event:InputEvent):Void
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 godot.Node.setProcessInput
.
To consume the input event and stop it propagating further to other nodes, godot.SceneTree.setInputAsHandled
can be called.
For gameplay input, godot.Node._UnhandledInput
and godot.Node._UnhandledKeyInput
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 orphan).
@:native("_PhysicsProcess")_PhysicsProcess(delta:Single):Void
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 godot.Node.setPhysicsProcess
.
Corresponds to the godot.Node.notificationPhysicsProcess
notification in godot.Object._Notification
.
Note: This method is only called if the node is present in the scene tree (i.e. if it's not orphan).
@:native("_Process")_Process(delta:Single):Void
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 godot.Node.setProcess
.
Corresponds to the godot.Node.notificationProcess
notification in godot.Object._Notification
.
Note: This method is only called if the node is present in the scene tree (i.e. if it's not orphan).
@:native("_Ready")_Ready():Void
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 godot.Node._Ready
callbacks get triggered first, and the parent node will receive the ready notification afterwards.
Corresponds to the godot.Node.notificationReady
notification in godot.Object._Notification
. See also the onready
keyword for variables.
Usually used for initialization. For even earlier initialization, may be used. See also godot.Node._EnterTree
.
Note: godot.Node._Ready
may be called only once for each node. After removing a node from the scene tree and adding again, _ready
will not be called for the second time. This can be bypassed with requesting another call with godot.Node.requestReady
, which may be called anywhere before adding the node again.
@:native("_UnhandledInput")_UnhandledInput(event:InputEvent):Void
Called when an godot.InputEvent
hasn't been consumed by godot.Node._Input
or any GUI. 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 godot.Node.setProcessUnhandledInput
.
To consume the input event and stop it propagating further to other nodes, godot.SceneTree.setInputAsHandled
can be called.
For gameplay input, this and godot.Node._UnhandledKeyInput
are usually a better fit than godot.Node._Input
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 orphan).
@:native("_UnhandledKeyInput")_UnhandledKeyInput(event:InputEventKey):Void
Called when an godot.InputEventKey
hasn't been consumed by godot.Node._Input
or any GUI. 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 godot.Node.setProcessUnhandledKeyInput
.
To consume the input event and stop it propagating further to other nodes, godot.SceneTree.setInputAsHandled
can be called.
For gameplay input, this and godot.Node._UnhandledInput
are usually a better fit than godot.Node._Input
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 orphan).
@:native("AddChild")addChild(node:Node, ?legibleUniqueName:Bool):Void
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 legible_unique_name
is true
, the child node will have a human-readable name based on the name of the node being instanced instead of its type.
Note: If the child node already has a parent, the function will fail. Use godot.Node.removeChild
first to remove the node from its current parent. For example:
if child_node.get_parent():
child_node.get_parent().remove_child(child_node)
add_child(child_node)
Note: If you want a child to be persisted to a godot.PackedScene
, you must set godot.Node.owner
in addition to calling godot.Node.addChild
. This is typically relevant for [https://docs.godotengine.org/en/3.4/tutorials/misc/running_code_in_the_editor.html](tool scripts) and [https://docs.godotengine.org/en/3.4/tutorials/plugins/editor/index.html](editor plugins). If godot.Node.addChild
is called without setting godot.Node.owner
, the newly added godot.Node
will not be visible in the scene tree, though it will be visible in the 2D/3D view.
@:native("AddChildBelowNode")addChildBelowNode(node:Node, childNode:Node, ?legibleUniqueName:Bool):Void
Adds child_node
as a child. The child is placed below the given node
in the list of children.
If legible_unique_name
is true
, the child node will have a human-readable name based on the name of the node being instanced instead of its type.
@:native("AddToGroup")addToGroup(group:String, ?persistent:Bool):Void
Adds the node to a group. Groups are helpers to name and organize a subset of nodes, for example "enemies" or "collectables". A node can be in any number of groups. Nodes can be assigned a group at any time, but will not be added until they are inside the scene tree (see godot.Node.isInsideTree
). See notes in the description, and the group methods in godot.SceneTree
.
The persistent
option is used when packing node to godot.PackedScene
and saving to file. Non-persistent groups aren't stored.
Note: For performance reasons, the order of node groups is not guaranteed. The order of node groups should not be relied upon as it can vary across project runs.
@:native("CanProcess")canProcess():Bool
Returns true
if the node can process while the scene tree is paused (see godot.Node.pauseMode
). Always returns true
if the scene tree is not paused, and false
if the node is not in the tree.
@:native("Duplicate")duplicate(?flags:Int):Node
Duplicates the node, returning a new node.
You can fine-tune the behavior using the flags
(see godot.Node_DuplicateFlags
).
Note: It will not work properly if the node contains a script with constructor arguments (i.e. needs to supply arguments to method). In that case, the node will be duplicated without a script.
@:native("FindNode")findNode(mask:String, ?recursive:Bool, ?owned:Bool):Node
Finds a descendant of this node whose name matches mask
as in String.match
(i.e. case-sensitive, but "*"
matches zero or more characters and "?"
matches any single character except "."
). Returns null
if no matching godot.Node
is found.
Note: It does not match against the full path, just against individual node names.
If owned
is true
, this method only finds nodes whose owner is this node. This is especially important for scenes instantiated through a script, because those scenes don't have an owner.
Note: As this method walks through all the descendants of the node, it is the slowest way to get a reference to another node. Whenever possible, consider using godot.Node.getNode
instead. To avoid using godot.Node.findNode
too often, consider caching the node reference into a variable.
@:native("FindParent")findParent(mask:String):Node
Finds the first parent of the current node whose name matches mask
as in String.match
(i.e. case-sensitive, but "*"
matches zero or more characters and "?"
matches any single character except "."
).
Note: It does not match against the full path, just against individual node names.
Note: As this method walks upwards in the scene tree, it can be slow in large, deeply nested scene trees. Whenever possible, consider using godot.Node.getNode
instead. To avoid using godot.Node.findParent
too often, consider caching the node reference into a variable.
@:native("GetChild")getChild(idx:Int):Node
Returns a child node by its index (see godot.Node.getChildCount
). This method is often used for iterating all children of a node.
To access a child node via its name, use godot.Node.getNode
.
@:native("GetGroups")getGroups():Array
Returns an array listing the groups that the node is a member of.
Note: For performance reasons, the order of node groups is not guaranteed. The order of node groups should not be relied upon as it can vary across project runs.
Note: The engine uses some group names internally (all starting with an underscore). To avoid conflicts with internal groups, do not add custom groups whose name starts with an underscore. To exclude internal groups while looping over godot.Node.getGroups
, use the following snippet:
# Stores the node's non-internal groups only (as an array of Strings).
var non_internal_groups = []
for group in get_groups():
if not group.begins_with("_"):
non_internal_groups.push_back(group)
@:native("GetIndex")getIndex():Int
Returns the node's index, i.e. its position among the siblings of its parent.
@:native("GetNetworkMaster")getNetworkMaster():Int
Returns the peer ID of the network master for this node. See godot.Node.setNetworkMaster
.
@:native("GetNode")getNode(path:NodePath):Node
Fetches a node. The godot.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 godot.Node.isInsideTree
).
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:
get_node("Sword")
get_node("Backpack/Dagger")
get_node("../Swamp/Alligator")
get_node("/root/MyGame")
@:native("GetNodeAndResource")getNodeAndResource(path:NodePath):Array
Fetches a node and one of its resources as specified by the godot.NodePath
's subname (e.g. Area2D/CollisionShape2D:shape
). If several nested resources are specified in the godot.NodePath
, the last one will be fetched.
The return value is an array of size 3: the first index points to the godot.Node
(or null
if not found), the second index points to the godot.Resource
(or null
if not found), and the third index is the remaining godot.NodePath
, if any.
For example, assuming that Area2D/CollisionShape2D
is a valid node and that its shape
property has been assigned a godot.RectangleShape2D
resource, one could have this kind of output:
print(get_node_and_resource("Area2D/CollisionShape2D")) # [[CollisionShape2D:1161], Null, ]
print(get_node_and_resource("Area2D/CollisionShape2D:shape")) # [[CollisionShape2D:1161], [RectangleShape2D:1156], ]
print(get_node_and_resource("Area2D/CollisionShape2D:shape:extents")) # [[CollisionShape2D:1161], [RectangleShape2D:1156], :extents]
@:native("GetNodeOrNull")getNodeOrNull(path:NodePath):Node
Similar to godot.Node.getNode
, but does not log an error if path
does not point to a valid godot.Node
.
@:native("GetParent")getParent():Node
Returns the parent node of the current node, or a null instance
if the node lacks a parent.
@:native("GetPath")getPath():NodePath
Returns the absolute path of the current node. This only works if the current node is inside the scene tree (see godot.Node.isInsideTree
).
@:native("GetPathTo")getPathTo(node:Node):NodePath
Returns the relative godot.NodePath
from this node to the specified node
. Both nodes must be in the same scene or the function will fail.
@:native("GetPhysicsProcessDeltaTime")getPhysicsProcessDeltaTime():Single
Returns the time elapsed (in seconds) since the last physics-bound frame (see godot.Node._PhysicsProcess
). This is always a constant value in physics processing unless the frames per second is changed via godot.Engine.iterationsPerSecond
.
@:native("GetPositionInParent")getPositionInParent():Int
Returns the node's order in the scene tree branch. For example, if called on the first child node the position is 0
.
@:native("GetProcessDeltaTime")getProcessDeltaTime():Single
Returns the time elapsed (in seconds) since the last process callback. This value may vary from frame to frame.
@:native("GetSceneInstanceLoadPlaceholder")getSceneInstanceLoadPlaceholder():Bool
Returns true
if this is an instance load placeholder. See godot.InstancePlaceholder
.
@:native("HasNode")hasNode(path:NodePath):Bool
Returns true
if the node that the godot.NodePath
points to exists.
@:native("HasNodeAndResource")hasNodeAndResource(path:NodePath):Bool
Returns true
if the godot.NodePath
points to a valid node and its subname points to a valid resource, e.g. Area2D/CollisionShape2D:shape
. Properties with a non-godot.Resource
type (e.g. nodes or primitive math types) are not considered resources.
@:native("IsAParentOf")isAParentOf(node:Node):Bool
Returns true
if the given node is a direct or indirect child of the current node.
@:native("IsDisplayedFolded")isDisplayedFolded():Bool
Returns true
if the node is folded (collapsed) in the Scene dock.
@:native("IsGreaterThan")isGreaterThan(node:Node):Bool
Returns true
if the given node occurs later in the scene hierarchy than the current node.
@:native("IsInGroup")isInGroup(group:String):Bool
Returns true
if this node is in the specified group. See notes in the description, and the group methods in godot.SceneTree
.
@:native("IsInsideTree")isInsideTree():Bool
Returns true
if this node is currently inside a godot.SceneTree
.
@:native("IsNetworkMaster")isNetworkMaster():Bool
Returns true
if the local system is the master of this node.
@:native("IsPhysicsProcessing")isPhysicsProcessing():Bool
Returns true
if physics processing is enabled (see godot.Node.setPhysicsProcess
).
@:native("IsPhysicsProcessingInternal")isPhysicsProcessingInternal():Bool
Returns true
if internal physics processing is enabled (see godot.Node.setPhysicsProcessInternal
).
@:native("IsProcessing")isProcessing():Bool
Returns true
if processing is enabled (see godot.Node.setProcess
).
@:native("IsProcessingInput")isProcessingInput():Bool
Returns true
if the node is processing input (see godot.Node.setProcessInput
).
@:native("IsProcessingInternal")isProcessingInternal():Bool
Returns true
if internal processing is enabled (see godot.Node.setProcessInternal
).
@:native("IsProcessingUnhandledInput")isProcessingUnhandledInput():Bool
Returns true
if the node is processing unhandled input (see godot.Node.setProcessUnhandledInput
).
@:native("IsProcessingUnhandledKeyInput")isProcessingUnhandledKeyInput():Bool
Returns true
if the node is processing unhandled key input (see godot.Node.setProcessUnhandledKeyInput
).
@:native("MoveChild")moveChild(childNode:Node, toPosition:Int):Void
Moves a child node to a different position (order) among the other children. Since calls, signals, etc are performed by tree order, changing the order of children nodes may be useful.
@:native("PrintStrayNodes")printStrayNodes():Void
Prints all stray nodes (nodes outside the godot.SceneTree
). Used for debugging. Works only in debug builds.
@:native("PrintTree")printTree():Void
Prints the tree to stdout. Used mainly for debugging purposes. This version displays the path relative to the current node, and is good for copy/pasting into the godot.Node.getNode
function.
Example output:
TheGame
TheGame/Menu
TheGame/Menu/Label
TheGame/Menu/Camera2D
TheGame/SplashScreen
TheGame/SplashScreen/Camera2D
@:native("PrintTreePretty")printTreePretty():Void
Similar to godot.Node.printTree
, this prints the tree to stdout. This version displays a more graphical representation similar to what is displayed in the scene inspector. It is useful for inspecting larger trees.
Example output:
┖╴TheGame
┠╴Menu
┃ ┠╴Label
┃ ┖╴Camera2D
┖╴SplashScreen
┖╴Camera2D
@:native("PropagateCall")propagateCall(method:String, ?args:Array, ?parentFirst:Bool):Void
Calls the given method (if present) with the arguments given in args
on this node and recursively on all its children. If the parent_first
argument is true
, the method will be called on the current node first, then on all its children. If parent_first
is false
, the children will be called first.
Parameters:
args | If the parameter is null, then the default value is new Godot.Collections.Array { } |
---|
@:native("PropagateNotification")propagateNotification(what:Int):Void
Notifies the current node and all its children recursively by calling godot.Object.notification
on all of them.
@:native("QueueFree")queueFree():Void
Queues a node for deletion at the end of the current frame. When deleted, all of its child nodes will be deleted as well. This method ensures it's safe to delete the node, contrary to godot.Object.free
. Use godot.Object.isQueuedForDeletion
to check whether a node will be deleted at the end of the frame.
Important: If you have a variable pointing to a node, it will not be assigned to null
once the node is freed. Instead, it will point to a previously freed instance and you should validate it with @GDScript.is_instance_valid
before attempting to call its methods or access its properties.
@:native("Raise")raise():Void
Moves this node to the bottom of parent node's children hierarchy. This is often useful in GUIs (godot.Control
nodes), because their order of drawing depends on their order in the tree. The top Node is drawn first, then any siblings below the top Node in the hierarchy are successively drawn on top of it. After using raise
, a Control will be drawn on top of its siblings.
@:native("RemoveAndSkip")removeAndSkip():Void
Removes a node and sets all its children as children of the parent node (if it exists). All event subscriptions that pass by the removed node will be unsubscribed.
@:native("RemoveChild")removeChild(node:Node):Void
Removes a child node. The node is NOT deleted and must be deleted manually.
Note: This function may set the godot.Node.owner
of the removed Node (or its descendants) to be null
, if that godot.Node.owner
is no longer a parent or ancestor.
@:native("RemoveFromGroup")removeFromGroup(group:String):Void
Removes a node from a group. See notes in the description, and the group methods in godot.SceneTree
.
@:native("ReplaceBy")replaceBy(node:Node, ?keepData:Bool):Void
Replaces a node in a scene by the given one. Subscriptions that pass through this node will be lost.
Note that the replaced node is not automatically freed, so you either need to keep it in a variable for later use or free it using godot.Object.free
.
@:native("RequestReady")requestReady():Void
Requests that _ready
be called again. Note that the method won't be called immediately, but is scheduled for when the node is added to the scene tree again (see godot.Node._Ready
). _ready
is called only for the node which requested it, which means that you need to request ready for each child if you want them to call _ready
too (in which case, _ready
will be called in the same order as it would normally).
@:native("Rpc")rpc(method:String, args:HaxeArray<Dynamic>):Dynamic
Sends a remote procedure call request for the given method
to peers on the network (and locally), optionally sending all additional arguments as arguments to the method called by the RPC. The call request will only be received by nodes with the same godot.NodePath
, including the exact same node name. Behaviour depends on the RPC configuration for the given method, see godot.Node.rpcConfig
. Methods are not exposed to RPCs by default. See also godot.Node.rset
and godot.Node.rsetConfig
for properties. Returns null
.
Note: You can only safely use RPCs on clients after you received the connected_to_server
signal from the godot.SceneTree
. You also need to keep track of the connection state, either by the godot.SceneTree
signals like server_disconnected
or by checking SceneTree.network_peer.get_connection_status() == CONNECTION_CONNECTED
.
@:native("RpcConfig")rpcConfig(method:String, mode:MultiplayerAPI_RPCMode):Void
Changes the RPC mode for the given method
to the given mode
. See godot.MultiplayerAPI_RPCMode
. An alternative is annotating methods and properties with the corresponding keywords (remote
, master
, puppet
, remotesync
, mastersync
, puppetsync
). By default, methods are not exposed to networking (and RPCs). See also godot.Node.rset
and godot.Node.rsetConfig
for properties.
@:native("RpcId")rpcId(peerId:Int, method:String, args:HaxeArray<Dynamic>):Dynamic
Sends a godot.Node.rpc
to a specific peer identified by peer_id
(see godot.NetworkedMultiplayerPeer.setTargetPeer
). Returns null
.
@:native("RpcUnreliable")rpcUnreliable(method:String, args:HaxeArray<Dynamic>):Dynamic
Sends a godot.Node.rpc
using an unreliable protocol. Returns null
.
@:native("RpcUnreliableId")rpcUnreliableId(peerId:Int, method:String, args:HaxeArray<Dynamic>):Dynamic
Sends a godot.Node.rpc
to a specific peer identified by peer_id
using an unreliable protocol (see godot.NetworkedMultiplayerPeer.setTargetPeer
). Returns null
.
@:native("Rset")rset(property:String, value:Dynamic):Void
Remotely changes a property's value on other peers (and locally). Behaviour depends on the RPC configuration for the given property, see godot.Node.rsetConfig
. See also godot.Node.rpc
for RPCs for methods, most information applies to this method as well.
@:native("RsetConfig")rsetConfig(property:String, mode:MultiplayerAPI_RPCMode):Void
Changes the RPC mode for the given property
to the given mode
. See godot.MultiplayerAPI_RPCMode
. An alternative is annotating methods and properties with the corresponding keywords (remote
, master
, puppet
, remotesync
, mastersync
, puppetsync
). By default, properties are not exposed to networking (and RPCs). See also godot.Node.rpc
and godot.Node.rpcConfig
for methods.
@:native("RsetId")rsetId(peerId:Int, property:String, value:Dynamic):Void
Remotely changes the property's value on a specific peer identified by peer_id
(see godot.NetworkedMultiplayerPeer.setTargetPeer
).
@:native("RsetUnreliable")rsetUnreliable(property:String, value:Dynamic):Void
Remotely changes the property's value on other peers (and locally) using an unreliable protocol.
@:native("RsetUnreliableId")rsetUnreliableId(peerId:Int, property:String, value:Dynamic):Void
Remotely changes property's value on a specific peer identified by peer_id
using an unreliable protocol (see godot.NetworkedMultiplayerPeer.setTargetPeer
).
@:native("SetDisplayFolded")setDisplayFolded(fold:Bool):Void
Sets the folded state of the node in the Scene dock.
@:native("SetNetworkMaster")setNetworkMaster(id:Int, ?recursive:Bool):Void
Sets the node's network master to the peer with the given peer ID. The network master is the peer that has authority over the node on the network. Useful in conjunction with the master
and puppet
keywords. Inherited from the parent node by default, which ultimately defaults to peer ID 1 (the server). If recursive
, the given peer is recursively set as the master for all children of this node.
@:native("SetPhysicsProcess")setPhysicsProcess(enable:Bool):Void
Enables or disables physics (i.e. fixed framerate) processing. When a node is being processed, it will receive a godot.Node.notificationPhysicsProcess
at a fixed (usually 60 FPS, see godot.Engine.iterationsPerSecond
to change) interval (and the godot.Node._PhysicsProcess
callback will be called if exists). Enabled automatically if godot.Node._PhysicsProcess
is overridden. Any calls to this before godot.Node._Ready
will be ignored.
@:native("SetPhysicsProcessInternal")setPhysicsProcessInternal(enable:Bool):Void
Enables or disables internal physics for this node. Internal physics processing happens in isolation from the normal godot.Node._PhysicsProcess
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 (godot.Node.setPhysicsProcess
). Only useful for advanced uses to manipulate built-in nodes' behavior.
Warning: Built-in Nodes rely on the internal processing for their own logic, so changing this value from your code may lead to unexpected behavior. Script access to this internal logic is provided for specific advanced uses, but is unsafe and not supported.
@:native("SetProcess")setProcess(enable:Bool):Void
Enables or disables processing. When a node is being processed, it will receive a godot.Node.notificationProcess
on every drawn frame (and the godot.Node._Process
callback will be called if exists). Enabled automatically if godot.Node._Process
is overridden. Any calls to this before godot.Node._Ready
will be ignored.
@:native("SetProcessInput")setProcessInput(enable:Bool):Void
Enables or disables input processing. This is not required for GUI controls! Enabled automatically if godot.Node._Input
is overridden. Any calls to this before godot.Node._Ready
will be ignored.
@:native("SetProcessInternal")setProcessInternal(enable:Bool):Void
Enables or disabled internal processing for this node. Internal processing happens in isolation from the normal godot.Node._Process
calls and is used by some nodes internally to guarantee proper functioning even if the node is paused or processing is disabled for scripting (godot.Node.setProcess
). Only useful for advanced uses to manipulate built-in nodes' behavior.
Warning: Built-in Nodes rely on the internal processing for their own logic, so changing this value from your code may lead to unexpected behavior. Script access to this internal logic is provided for specific advanced uses, but is unsafe and not supported.
@:native("SetProcessUnhandledInput")setProcessUnhandledInput(enable:Bool):Void
Enables unhandled input processing. This is not required for GUI controls! It enables the node to receive all input that was not previously handled (usually by a godot.Control
). Enabled automatically if godot.Node._UnhandledInput
is overridden. Any calls to this before godot.Node._Ready
will be ignored.
@:native("SetProcessUnhandledKeyInput")setProcessUnhandledKeyInput(enable:Bool):Void
Enables unhandled key input processing. Enabled automatically if godot.Node._UnhandledKeyInput
is overridden. Any calls to this before godot.Node._Ready
will be ignored.
@:native("SetSceneInstanceLoadPlaceholder")setSceneInstanceLoadPlaceholder(loadPlaceholder:Bool):Void
Sets whether this is an instance load placeholder. See godot.InstancePlaceholder
.
@:native("UpdateConfigurationWarning")updateConfigurationWarning():Void
Updates the warning displayed for this node in the Scene Dock.
Use godot.Node._GetConfigurationWarning
to setup the warning message to display.
Defined by Object
@:native("_Get")_Get(property:String):Dynamic
Virtual method which can be overridden to customize the return value of godot.Object.get
.
Returns the given property. Returns null
if the property
does not exist.
@:native("_GetPropertyList")_GetPropertyList():Array
Virtual method which can be overridden to customize the return value of godot.Object.getPropertyList
.
Returns the object's property list as an godot.Collections_Array
of dictionaries.
Each property's godot.Collections_Dictionary
must contain at least name: String
and type: int
(see godot.Variant_Type
) entries. Optionally, it can also include hint: int
(see godot.PropertyHint
), hint_string: String
, and usage: int
(see godot.PropertyUsageFlags
).
@:native("_Notification")_Notification(what:Int):Void
Called whenever the object receives a notification, which is identified in what
by a constant. The base godot.Object
has two constants godot.Object.notificationPostinitialize
and godot.Object.notificationPredelete
, but subclasses such as godot.Node
define a lot more notifications which are also received by this method.
@:native("_Set")_Set(property:String, value:Dynamic):Bool
Virtual method which can be overridden to customize the return value of godot.Object.set
.
Sets a property. Returns true
if the property
exists.
@:native("AddUserSignal")addUserSignal(signal:String, ?arguments:Array):Void
Adds a user-defined signal
. Arguments are optional, but can be added as an godot.Collections_Array
of dictionaries, each containing name: String
and type: int
(see godot.Variant_Type
) entries.
Parameters:
arguments | If the parameter is null, then the default value is new Godot.Collections.Array { } |
---|
@:native("Call")call(method:String, args:HaxeArray<Dynamic>):Dynamic
Calls the method
on the object and returns the result. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example:
call("set", "position", Vector2(42.0, 0.0))
Note: In C#, the method name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined methods where you should use the same convention as in the C# source (typically PascalCase).
@:native("CallDeferred")callDeferred(method:String, args:HaxeArray<Dynamic>):Void
Calls the method
on the object during idle time. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example:
call_deferred("set", "position", Vector2(42.0, 0.0))
Note: In C#, the method name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined methods where you should use the same convention as in the C# source (typically PascalCase).
@:native("Callv")callv(method:String, argArray:Array):Dynamic
Calls the method
on the object and returns the result. Contrarily to godot.Object.call
, this method does not support a variable number of arguments but expects all parameters to be via a single godot.Collections_Array
.
callv("set", [ "position", Vector2(42.0, 0.0) ])
@:native("CanTranslateMessages")canTranslateMessages():Bool
Returns true
if the object can translate strings. See godot.Object.setMessageTranslation
and godot.Object.tr
.
@:native("Connect")connect(signal:String, target:Object, method:String, ?binds:Array, ?flags:UInt):Error
Connects a signal
to a method
on a target
object. Pass optional binds
to the call as an godot.Collections_Array
of parameters. These parameters will be passed to the method after any parameter used in the call to godot.Object.emitSignal
. Use flags
to set deferred or one-shot connections. See godot.Object_ConnectFlags
constants.
A signal
can only be connected once to a method
. It will print an error if already connected, unless the signal was connected with godot.Object_ConnectFlags.referenceCounted
. To avoid this, first, use godot.Object.isConnected
to check for existing connections.
If the target
is destroyed in the game's lifecycle, the connection will be lost.
Examples:
connect("pressed", self, "_on_Button_pressed") # BaseButton signal
connect("text_entered", self, "_on_LineEdit_text_entered") # LineEdit signal
connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # User-defined signal
An example of the relationship between binds
passed to godot.Object.connect
and parameters used when calling godot.Object.emitSignal
:
connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # weapon_type and damage are passed last
emit_signal("hit", "Dark lord", 5) # "Dark lord" and 5 are passed first
func _on_Player_hit(hit_by, level, weapon_type, damage):
print("Hit by %s (lvl %d) with weapon %s for %d damage" % [hit_by, level, weapon_type, damage])
Parameters:
binds | If the parameter is null, then the default value is new Godot.Collections.Array { } |
---|
@:native("Disconnect")disconnect(signal:String, target:Object, method:String):Void
Disconnects a signal
from a method
on the given target
.
If you try to disconnect a connection that does not exist, the method will print an error. Use godot.Object.isConnected
to ensure that the connection exists.
@:native("Dispose")dispose():Void
@:native("Dispose")@:protectedDispose(disposing:Bool):Void
Disposes of this godot.Object
.
@:native("EmitSignal")emitSignal(signal:String, args:HaxeArray<Dynamic>):Void
Emits the given signal
. The signal must exist, so it should be a built-in signal of this class or one of its parent classes, or a user-defined signal. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example:
emit_signal("hit", weapon_type, damage)
emit_signal("game_over")
@:native("Free")free():Void
Deletes the object from memory immediately. For godot.Node
s, you may want to use godot.Node.queueFree
to queue the node for safe deletion at the end of the current frame.
Important: If you have a variable pointing to an object, it will not be assigned to null
once the object is freed. Instead, it will point to a previously freed instance and you should validate it with @GDScript.is_instance_valid
before attempting to call its methods or access its properties.
@:native("Get")get(property:String):Dynamic
Returns the Variant
value of the given property
. If the property
doesn't exist, this will return null
.
Note: In C#, the property name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined properties where you should use the same convention as in the C# source (typically PascalCase).
@:native("GetClass")getClass():String
Returns the object's class as a String
. See also godot.Object.isClass
.
Note: godot.Object.getClass
does not take class_name
declarations into account. If the object has a class_name
defined, the base class name will be returned instead.
@:native("GetIncomingConnections")getIncomingConnections():Array
Returns an godot.Collections_Array
of dictionaries with information about signals that are connected to the object.
Each godot.Collections_Dictionary
contains three String entries:
-
source
is a reference to the signal emitter. -
signal_name
is the name of the connected signal. -
method_name
is the name of the method to which the signal is connected.
@:native("GetIndexed")getIndexed(property:NodePath):Dynamic
Gets the object's property indexed by the given godot.NodePath
. The node path should be relative to the current object and can use the colon character (:
) to access nested properties. Examples: "position:x"
or "material:next_pass:blend_mode"
.
Note: Even though the method takes godot.NodePath
argument, it doesn't support actual paths to godot.Node
s in the scene tree, only colon-separated sub-property paths. For the purpose of nodes, use godot.Node.getNodeAndResource
instead.
@:native("GetInstanceId")getInstanceId():UInt64
Returns the object's unique instance ID.
This ID can be saved in godot.EncodedObjectAsID
, and can be used to retrieve the object instance with @GDScript.instance_from_id
.
@:native("GetMeta")getMeta(name:String):Dynamic
Returns the object's metadata entry for the given name
.
@:native("GetMethodList")getMethodList():Array
Returns the object's methods and their signatures as an godot.Collections_Array
.
@:native("GetPropertyList")getPropertyList():Array
Returns the object's property list as an godot.Collections_Array
of dictionaries.
Each property's godot.Collections_Dictionary
contain at least name: String
and type: int
(see godot.Variant_Type
) entries. Optionally, it can also include hint: int
(see godot.PropertyHint
), hint_string: String
, and usage: int
(see godot.PropertyUsageFlags
).
@:native("GetScript")getScript():Reference
Returns the object's godot.Script
instance, or null
if none is assigned.
@:native("GetSignalConnectionList")getSignalConnectionList(signal:String):Array
Returns an godot.Collections_Array
of connections for the given signal
.
@:native("GetSignalList")getSignalList():Array
Returns the list of signals as an godot.Collections_Array
of dictionaries.
@:native("HasMeta")hasMeta(name:String):Bool
Returns true
if a metadata entry is found with the given name
.
@:native("HasMethod")hasMethod(method:String):Bool
Returns true
if the object contains the given method
.
@:native("HasUserSignal")hasUserSignal(signal:String):Bool
Returns true
if the given user-defined signal
exists. Only signals added using godot.Object.addUserSignal
are taken into account.
@:native("IsBlockingSignals")isBlockingSignals():Bool
Returns true
if signal emission blocking is enabled.
@:native("IsClass")isClass(class_:String):Bool
Returns true
if the object inherits from the given class
. See also godot.Object.getClass
.
Note: godot.Object.isClass
does not take class_name
declarations into account. If the object has a class_name
defined, godot.Object.isClass
will return false
for that name.
@:native("IsConnected")isConnected(signal:String, target:Object, method:String):Bool
Returns true
if a connection exists for a given signal
, target
, and method
.
@:native("IsQueuedForDeletion")isQueuedForDeletion():Bool
Returns true
if the godot.Node.queueFree
method was called for the object.
@:native("Notification")notification(what:Int, ?reversed:Bool):Void
Send a given notification to the object, which will also trigger a call to the godot.Object._Notification
method of all classes that the object inherits from.
If reversed
is true
, godot.Object._Notification
is called first on the object's own class, and then up to its successive parent classes. If reversed
is false
, godot.Object._Notification
is called first on the highest ancestor (godot.Object
itself), and then down to its successive inheriting classes.
@:native("PropertyListChangedNotify")propertyListChangedNotify():Void
Notify the editor that the property list has changed, so that editor plugins can take the new values into account. Does nothing on export builds.
@:native("RemoveMeta")removeMeta(name:String):Void
Removes a given entry from the object's metadata. See also godot.Object.setMeta
.
@:native("Set")set(property:String, value:Dynamic):Void
Assigns a new value to the given property. If the property
does not exist or the given value's type doesn't match, nothing will happen.
Note: In C#, the property name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined properties where you should use the same convention as in the C# source (typically PascalCase).
@:native("SetBlockSignals")setBlockSignals(enable:Bool):Void
If set to true
, signal emission is blocked.
@:native("SetDeferred")setDeferred(property:String, value:Dynamic):Void
Assigns a new value to the given property, after the current frame's physics step. This is equivalent to calling godot.Object.set
via godot.Object.callDeferred
, i.e. call_deferred("set", property, value)
.
Note: In C#, the property name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined properties where you should use the same convention as in the C# source (typically PascalCase).
@:native("SetIndexed")setIndexed(property:NodePath, value:Dynamic):Void
Assigns a new value to the property identified by the godot.NodePath
. The node path should be relative to the current object and can use the colon character (:
) to access nested properties. Example:
set_indexed("position", Vector2(42, 0))
set_indexed("position:y", -10)
print(position) # (42, -10)
@:native("SetMessageTranslation")setMessageTranslation(enable:Bool):Void
Defines whether the object can translate strings (with calls to godot.Object.tr
). Enabled by default.
@:native("SetMeta")setMeta(name:String, value:Dynamic):Void
Adds, changes or removes a given entry in the object's metadata. Metadata are serialized and can take any Variant
value.
To remove a given entry from the object's metadata, use godot.Object.removeMeta
. Metadata is also removed if its value is set to null
. This means you can also use set_meta("name", null)
to remove metadata for "name"
.
@:native("SetScript")setScript(script:Reference):Void
Assigns a script to the object. Each object can have a single script assigned to it, which are used to extend its functionality.
If the object already had a script, the previous script instance will be freed and its variables and state will be lost. The new script's method will be called.
@:native("ToSignal")toSignal(source:Object, signal:String):SignalAwaiter
Returns a new godot.SignalAwaiter
awaiter configured to complete when the instance
source
emits the signal specified by the signal
parameter.
Parameters:
source | The instance the awaiter will be listening to. |
---|---|
signal | The signal the awaiter will be waiting for. This sample prints a message once every frame up to 100 times.
|
Returns:
A godot.SignalAwaiter
that completes when
source
emits the signal
.
@:native("ToString")toString():String
@:native("Tr")tr(message:String):String
Translates a message using translation catalogs configured in the Project Settings.
Only works if message translation is enabled (which it is by default), otherwise it returns the message
unchanged. See godot.Object.setMessageTranslation
.