pub struct RichTextLabel { /* private fields */ }
Expand description

core class RichTextLabel inherits Control (manually managed).

This class has related types in the rich_text_label module.

Official documentation

See the documentation of this class in the Godot engine’s official documentation. The method descriptions are generated from it and typically contain code samples in GDScript, not Rust.

Memory management

Non-reference-counted objects, such as the ones of this type, are usually owned by the engine.

RichTextLabel is a reference-only type. Persistent references can only exist in the unsafe Ref<RichTextLabel> form.

In the cases where Rust code owns an object of this type, for example if the object was just created on the Rust side and not passed to the engine yet, ownership should be either given to the engine or the object must be manually destroyed using Ref::free, or Ref::queue_free if it is a Node.

Class hierarchy

RichTextLabel inherits methods from:

Safety

All types in the Godot API have interior mutability in Rust parlance. To enforce that the official thread-safety guidelines are followed, the typestate pattern is used in the Ref and TRef smart pointers, and the Instance API. The typestate Ownership in these types tracks whether ownership is unique, shared, or exclusive to the current thread. For more information, see the type-level documentation on Ref.

Implementations

Constants

Creates a new instance of this object.

Because this type is not reference counted, the lifetime of the returned object is not automatically managed.

Immediately after creation, the object is owned by the caller, and can be passed to the engine (in which case the engine will be responsible for destroying the object) or destroyed manually using Ref::free, or preferably Ref::queue_free if it is a Node.

Adds an image’s opening and closing tags to the tag stack, optionally providing a width and height to resize the image. If width or height is set to 0, the image size will be adjusted in order to keep the original aspect ratio.

Default Arguments
  • width - 0
  • height - 0
  • align - 2

Adds raw non-BBCode-parsed text to the tag stack.

Parses bbcode and adds tags to the tag stack as needed. Note: Using this method, you can’t close a tag that was opened in a previous append_bbcode call. This is done to improve performance, especially when updating large RichTextLabels since rebuilding the whole BBCode every time would be slower. If you absolutely need to close a tag in a future method call, append the [bbcode_text][Self::bbcode_text] instead of using append_bbcode. Note: This method internals’ can’t possibly fail, but an error code is returned for backwards compatibility, which will always be [OK][Self::OK].

Clears the tag stack and sets [bbcode_text][Self::bbcode_text] to an empty string.

Clears the current selection.

The label’s text in BBCode format. Is not representative of manual modifications to the internal tag stack. Erases changes made by other methods when edited. Note: It is unadvised to use the += operator with bbcode_text (e.g. bbcode_text += "some string") as it replaces the whole text and can cause slowdowns. It will also erase all BBCode that was added to stack using push_* methods. Use append_bbcode for adding text instead, unless you absolutely need to close a tag that was opened in an earlier method call.

Returns the height of the content.

The currently installed custom effects. This is an array of RichTextEffects. To add a custom effect, it’s more convenient to use install_effect.

Returns the total number of newlines in the tag stack’s text tags. Considers wrapped text as one line.

The range of characters to display, as a [float][float] between 0.0 and 1.0. When assigned an out of range value, it’s the same as assigning 1.0. Note: Setting this property updates visible_characters based on current get_total_character_count.

Returns the current selection text. Does not include BBCodes.

The number of spaces associated with a single tab length. Does not affect \t in text tags, only indent tags.

The raw text of the label. When set, clears the tag stack and adds a raw text tag to the top of it. Does not parse BBCodes. Does not modify [bbcode_text][Self::bbcode_text].

Returns the total number of characters from text tags. Does not include BBCodes.

Returns the vertical scrollbar. Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their [CanvasItem.visible][CanvasItem::visible] property.

The restricted number of characters to display in the label. If -1, all characters will be displayed. Note: Setting this property updates percent_visible based on current get_total_character_count.

Returns the number of visible lines.

Installs a custom effect. effect should be a valid RichTextEffect.

If true, the selected text will be deselected when focus is lost.

If true, the label’s height will be automatically updated to fit its content. Note: This property is used as a workaround to fix issues with RichTextLabel in Containers, but it’s unreliable in some cases and will be removed in future versions.

If true, the label underlines meta tags such as [url][url]{text}[/url].

If true, the label uses the custom font color.

If true, the scrollbar is visible. Setting this to false does not block scrolling completely. See scroll_to_line.

If true, the window scrolls down to display new content automatically.

If true, the label allows text selection.

If true, the label uses BBCode formatting. Note: Trying to alter the RichTextLabel’s text with add_text will reset this to false. Use instead append_bbcode to preserve BBCode formatting.

Adds a newline tag to the tag stack.

The assignment version of append_bbcode. Clears the tag stack and inserts the new content. Note: This method internals’ can’t possibly fail, but an error code is returned for backwards compatibility, which will always be [OK][Self::OK].

Parses BBCode parameter expressions into a dictionary.

Terminates the current tag. Use after push_* methods to close BBCodes manually. Does not need to follow add_* methods.

Adds an [align][align] tag based on the given align value. See Align for possible values.

Adds a [font][font] tag with a bold font to the tag stack. This is the same as adding a ** tag if not currently in a _ tag.

Adds a [font][font] tag with a bold italics font to the tag stack.

Adds a [cell][cell] tag to the tag stack. Must be inside a [table][table] tag. See push_table for details.

Adds a [color][color] tag to the tag stack.

Adds a [font][font] tag to the tag stack. Overrides default fonts for its duration.

Adds an [indent][indent] tag to the tag stack. Multiplies level by current tab_size to determine new margin length.

Adds a [font][font] tag with a italics font to the tag stack. This is the same as adding a _ tag if not currently in a ** tag.

Adds a [list][list] tag to the tag stack. Similar to the BBCodes [ol][ol] or [ul][ul], but supports more list types. Not fully implemented!

Adds a [meta][meta] tag to the tag stack. Similar to the BBCode [{text}](something), but supports non-String metadata types.

Adds a [font][font] tag with a monospace font to the tag stack.

Adds a [font][font] tag with a normal font to the tag stack.

Adds a [s][s] tag to the tag stack.

Adds a [table=columns] tag to the tag stack.

Adds a [u][u] tag to the tag stack.

Removes a line of content from the label. Returns true if the line exists. The line argument is the index of the line to remove, it can take values in the interval [0, get_line_count() - 1].

Scrolls the window’s top line to match line.

The label’s text in BBCode format. Is not representative of manual modifications to the internal tag stack. Erases changes made by other methods when edited. Note: It is unadvised to use the += operator with bbcode_text (e.g. bbcode_text += "some string") as it replaces the whole text and can cause slowdowns. It will also erase all BBCode that was added to stack using push_* methods. Use append_bbcode for adding text instead, unless you absolutely need to close a tag that was opened in an earlier method call.

If true, the selected text will be deselected when focus is lost.

The currently installed custom effects. This is an array of RichTextEffects. To add a custom effect, it’s more convenient to use install_effect.

If true, the label’s height will be automatically updated to fit its content. Note: This property is used as a workaround to fix issues with RichTextLabel in Containers, but it’s unreliable in some cases and will be removed in future versions.

If true, the label underlines meta tags such as [url][url]{text}[/url].

If true, the label uses the custom font color.

The range of characters to display, as a [float][float] between 0.0 and 1.0. When assigned an out of range value, it’s the same as assigning 1.0. Note: Setting this property updates visible_characters based on current get_total_character_count.

If true, the scrollbar is visible. Setting this to false does not block scrolling completely. See scroll_to_line.

If true, the window scrolls down to display new content automatically.

If true, the label allows text selection.

The number of spaces associated with a single tab length. Does not affect \t in text tags, only indent tags.

Edits the selected column’s expansion options. If expand is true, the column expands in proportion to its expansion ratio versus the other columns’ ratios. For example, 2 columns with ratios 3 and 4 plus 70 pixels in available width would expand 30 and 40 pixels, respectively. If expand is false, the column will not contribute to the total ratio.

The raw text of the label. When set, clears the tag stack and adds a raw text tag to the top of it. Does not parse BBCodes. Does not modify [bbcode_text][Self::bbcode_text].

If true, the label uses BBCode formatting. Note: Trying to alter the RichTextLabel’s text with add_text will reset this to false. Use instead append_bbcode to preserve BBCode formatting.

The restricted number of characters to display in the label. If -1, all characters will be displayed. Note: Setting this property updates percent_visible based on current get_total_character_count.

Methods from Deref<Target = Control>

Marks an input event as handled. Once you accept an input event, it stops propagating, even to nodes listening to [Node._unhandled_input][Node::_unhandled_input] or [Node._unhandled_key_input][Node::_unhandled_key_input].

Sample code is GDScript unless otherwise noted.

Creates a local override for a theme Color with the specified name. Local overrides always take precedence when fetching theme items for the control. See also get_color, remove_color_override. Example of overriding a label’s color and resetting it later:

$MyLabel.add_color_override("font_color", Color(1, 0.5, 0))
$MyLabel.add_color_override("font_color", get_color("font_color", "Label"))

Creates a local override for a theme constant with the specified name. Local overrides always take precedence when fetching theme items for the control. See also get_constant, remove_constant_override.

Creates a local override for a theme Font with the specified name. Local overrides always take precedence when fetching theme items for the control. Note: An override can be removed by assigning it a null value. This behavior is deprecated and will be removed in 4.0, use remove_font_override instead. See also get_font.

Creates a local override for a theme icon with the specified name. Local overrides always take precedence when fetching theme items for the control. Note: An override can be removed by assigning it a null value. This behavior is deprecated and will be removed in 4.0, use remove_icon_override instead. See also get_icon.

Creates a local override for a theme shader with the specified name. Local overrides always take precedence when fetching theme items for the control. Note: An override can be removed by assigning it a null value. This behavior is deprecated and will be removed in 4.0, use remove_shader_override instead.

Sample code is GDScript unless otherwise noted.

Creates a local override for a theme StyleBox with the specified name. Local overrides always take precedence when fetching theme items for the control. Note: An override can be removed by assigning it a null value. This behavior is deprecated and will be removed in 4.0, use remove_stylebox_override instead. See also get_stylebox. Example of modifying a property in a StyleBox by duplicating it:

var new_stylebox_normal = $MyButton.get_stylebox("normal").duplicate()
new_stylebox_normal.border_width_top = 3
new_stylebox_normal.border_color = Color(0, 1, 0.5)
$MyButton.add_stylebox_override("normal", new_stylebox_normal)
$MyButton.add_stylebox_override("normal", null)

Finds the next (below in the tree) Control that can receive the focus.

Finds the previous (above in the tree) Control that can receive the focus.

Forces drag and bypasses [get_drag_data][Self::get_drag_data] and set_drag_preview by passing data and preview. Drag will start even if the mouse is neither over nor pressed on this control. The methods [can_drop_data][Self::can_drop_data] and [drop_data][Self::drop_data] must be implemented on controls that want to receive drop data.

Anchors the top edge of the node to the origin, the center or the end of its parent control. It changes how the top margin updates when the node moves or changes size. You can use one of the Anchor constants for convenience.

Returns [margin_left][Self::margin_left] and [margin_top][Self::margin_top]. See also [rect_position][Self::rect_position].

Sample code is GDScript unless otherwise noted.

Returns a Color from the first matching Theme in the tree if that Theme has a color item with the specified name and theme_type. If theme_type is omitted the class name of the current control is used as the type, or theme_type_variation if it is defined. If the type is a class name its parent classes are also checked, in order of inheritance. For the current control its local overrides are considered first (see add_color_override), then its assigned theme. After the current control, each parent control and its assigned theme are considered; controls without a theme assigned are skipped. If no matching Theme is found in the tree, a custom project Theme (see [member ProjectSettings.gui/theme/custom]) and the default Theme are used.

func _ready():
    modulate = get_color("font_color")
    modulate = get_color("font_color", "Button")
Default Arguments
  • theme_type - ""

Returns combined minimum size from [rect_min_size][Self::rect_min_size] and get_minimum_size.

Returns a constant from the first matching Theme in the tree if that Theme has a constant item with the specified name and theme_type. See get_color for details.

Default Arguments
  • theme_type - ""

Returns the mouse cursor shape the control displays on mouse hover. See CursorShape.

Default Arguments
  • position - Vector2( 0, 0 )

The minimum size of the node’s bounding rectangle. If you set it to a value greater than (0, 0), the node’s bounding rectangle will always have at least this size, even if its content is smaller. If it’s set to (0, 0), the node sizes automatically to fit its content, be it a texture or child nodes.

The default cursor shape for this control. Useful for Godot plugins and applications or games that use the system’s mouse cursors. Note: On Linux, shapes may vary depending on the cursor theme of the system.

Returns [margin_right][Self::margin_right] and [margin_bottom][Self::margin_bottom].

The focus access mode for the control (None, Click or All). Only one Control can be focused at the same time, and it will receive keyboard signals.

Tells Godot which node it should give keyboard focus to if the user presses the top arrow on the keyboard or top on a gamepad by default. You can change the key by editing the ui_top input action. The node must be a Control. If this property is not set, Godot will give focus to the closest Control to the bottom of this one.

Tells Godot which node it should give keyboard focus to if the user presses Tab on a keyboard by default. You can change the key by editing the ui_focus_next input action. If this property is not set, Godot will select a “best guess” based on surrounding nodes in the scene tree.

Returns the control that has the keyboard focus or null if none.

Tells Godot which node it should give keyboard focus to if the user presses Shift+Tab on a keyboard by default. You can change the key by editing the ui_focus_prev input action. If this property is not set, Godot will select a “best guess” based on surrounding nodes in the scene tree.

Returns a Font from the first matching Theme in the tree if that Theme has a font item with the specified name and theme_type. See get_color for details.

Default Arguments
  • theme_type - ""

The node’s global position, relative to the world (usually to the top-left corner of the window).

Returns the position and size of the control relative to the top-left corner of the screen. See [rect_position][Self::rect_position] and [rect_size][Self::rect_size].

Controls the direction on the horizontal axis in which the control should grow if its horizontal minimum size is changed to be greater than its current size, as the control always has to be at least the minimum size.

Tells the parent Container nodes how they should resize and place the node on the X axis. Use one of the SizeFlags constants to change the flags. See the constants to learn what each does.

Returns an icon from the first matching Theme in the tree if that Theme has an icon item with the specified name and theme_type. See get_color for details.

Default Arguments
  • theme_type - ""

Distance between the node’s top edge and its parent control, based on [anchor_top][Self::anchor_top]. Margins are often controlled by one or multiple parent Container nodes, so you should not modify them manually if your node is a direct child of a Container. Margins update automatically when you move or resize the node.

Returns the minimum size for this control. See [rect_min_size][Self::rect_min_size].

Controls whether the control will be able to receive mouse button input events through [_gui_input][Self::_gui_input] and how these events should be handled. Also controls whether the control can receive the mouse_entered, and mouse_exited signals. See the constants to learn what each does.

Returns the width/height occupied in the parent control.

Returns the parent control node.

Enables whether input should propagate when you close the control as modal. If false, stops event handling at the viewport input event handling. The viewport first hides the modal and after marks the input as handled.

By default, the node’s pivot is its top-left corner. When you change its [rect_rotation][Self::rect_rotation] or [rect_scale][Self::rect_scale], it will rotate or scale around this pivot. Set this property to [rect_size][Self::rect_size] / 2 to pivot around the Control’s center.

The node’s position, relative to its parent. It corresponds to the rectangle’s top-left corner. The property is not affected by [rect_pivot_offset][Self::rect_pivot_offset].

Returns the position and size of the control relative to the top-left corner of the parent Control. See [rect_position][Self::rect_position] and [rect_size][Self::rect_size].

Returns the rotation (in radians).

The node’s rotation around its pivot, in degrees. See [rect_pivot_offset][Self::rect_pivot_offset] to change the pivot’s position.

The node’s scale, relative to its [rect_size][Self::rect_size]. Change this property to scale the node around its [rect_pivot_offset][Self::rect_pivot_offset]. The Control’s [hint_tooltip][Self::hint_tooltip] will also scale according to this value. Note: This property is mainly intended to be used for animation purposes. Text inside the Control will look pixelated or blurry when the Control is scaled. To support multiple resolutions in your project, use an appropriate viewport stretch mode as described in the [documentation]documentation instead of scaling Controls individually. Note: If the Control node is a child of a Container node, the scale will be reset to Vector2(1, 1) when the scene is instanced. To set the Control’s scale when it’s instanced, wait for one frame using yield(get_tree(), "idle_frame") then set its [rect_scale][Self::rect_scale] property.

The size of the node’s bounding rectangle, in pixels. Container nodes update this property automatically.

If the node and at least one of its neighbours uses the SIZE_EXPAND size flag, the parent Container will let it take more or less space depending on this property. If this node has a stretch ratio of 2 and its neighbour a ratio of 1, this node will take two thirds of the available space.

Returns a StyleBox from the first matching Theme in the tree if that Theme has a stylebox item with the specified name and theme_type. See get_color for details.

Default Arguments
  • theme_type - ""

Changing this property replaces the current Theme resource this node and all its Control children use.

Returns the default font from the first matching Theme in the tree if that Theme has a valid Theme.default_font value. See get_color for details.

The name of a theme type variation used by this Control to look up its own theme items. When empty, the class name of the node is used (e.g. Button for the Button control), as well as the class names of all parent classes (in order of inheritance). When set, this property gives the highest priority to the type of the specified name. This type can in turn extend another type, forming a dependency chain. See Theme.set_type_variation. If the theme item cannot be found using this type or its base types, lookup falls back on the class names. Note: To look up Control’s own items use various get_* methods without specifying theme_type. Note: Theme items are looked for in the tree order, from branch to root, where each Control node is checked for its theme property. The earliest match against any type/class name is returned. The project-level Theme and the default Theme are checked last.

Returns the tooltip, which will appear when the cursor is resting over this control. See [hint_tooltip][Self::hint_tooltip].

Default Arguments
  • at_position - Vector2( 0, 0 )

Controls the direction on the vertical axis in which the control should grow if its vertical minimum size is changed to be greater than its current size, as the control always has to be at least the minimum size.

Tells the parent Container nodes how they should resize and place the node on the Y axis. Use one of the SizeFlags constants to change the flags. See the constants to learn what each does.

Sample code is GDScript unless otherwise noted.

Creates an InputEventMouseButton that attempts to click the control. If the event is received, the control acquires focus.

func _process(delta):
    grab_click_focus() #when clicking another Control node, this node will be clicked instead

Steal the focus from another control and become the focused control (see focus_mode). Note: Using this method together with Object.call_deferred makes it more reliable, especially when called inside [Node._ready][Node::_ready].

Returns true if there is a matching Theme in the tree that has a color item with the specified name and theme_type. See get_color for details.

Default Arguments
  • theme_type - ""

Returns true if there is a local override for a theme Color with the specified name in this Control node. See add_color_override.

Returns true if there is a matching Theme in the tree that has a constant item with the specified name and theme_type. See get_color for details.

Default Arguments
  • theme_type - ""

Returns true if there is a local override for a theme constant with the specified name in this Control node. See add_constant_override.

Returns true if this is the current focused control. See focus_mode.

Returns true if there is a matching Theme in the tree that has a font item with the specified name and theme_type. See get_color for details.

Default Arguments
  • theme_type - ""

Returns true if there is a local override for a theme Font with the specified name in this Control node. See add_font_override.

Returns true if there is a matching Theme in the tree that has an icon item with the specified name and theme_type. See get_color for details.

Default Arguments
  • theme_type - ""

Returns true if there is a local override for a theme icon with the specified name in this Control node. See add_icon_override.

Returns true if there is a local override for a theme shader with the specified name in this Control node. See add_shader_override.

Returns true if there is a matching Theme in the tree that has a stylebox item with the specified name and theme_type. See get_color for details.

Default Arguments
  • theme_type - ""

Returns true if there is a local override for a theme StyleBox with the specified name in this Control node. See add_stylebox_override.

Enables whether rendering of CanvasItem based children should be clipped to this control’s rectangle. If true, parts of a child which would be visibly outside of this control’s rectangle will not be rendered.

Returns true if a drag operation is successful. Alternative to Viewport.gui_is_drag_successful. Best used with Node.NOTIFICATION_DRAG_END.

Invalidates the size cache in this node and in parent nodes up to toplevel. Intended to be used with get_minimum_size when the return value is changed. Setting [rect_min_size][Self::rect_min_size] directly calls this method automatically.

Give up the focus. No other control will be able to receive keyboard input.

Removes a theme override for a Color with the given name.

Removes a theme override for a constant with the given name.

Removes a theme override for a Font with the given name.

Removes a theme override for an icon with the given name.

Removes a theme override for a shader with the given name.

Removes a theme override for a StyleBox with the given name.

Sets the anchor identified by margin constant from Margin enum to value anchor. A setter method for [anchor_bottom][Self::anchor_bottom], [anchor_left][Self::anchor_left], [anchor_right][Self::anchor_right] and [anchor_top][Self::anchor_top]. If keep_margin is true, margins aren’t updated after this operation. If push_opposite_anchor is true and the opposite anchor overlaps this anchor, the opposite one will have its value overridden. For example, when setting left anchor to 1 and the right anchor has value of 0.5, the right anchor will also get value of 1. If push_opposite_anchor was false, the left anchor would get value 0.5.

Default Arguments
  • keep_margin - false
  • push_opposite_anchor - true

Works the same as set_anchor, but instead of keep_margin argument and automatic update of margin, it allows to set the margin offset yourself (see set_margin).

Default Arguments
  • push_opposite_anchor - false

Sets both anchor preset and margin preset. See set_anchors_preset and set_margins_preset.

Default Arguments
  • resize_mode - 0
  • margin - 0

Sets the anchors to a preset from [enum Control.LayoutPreset] enum. This is the code equivalent to using the Layout menu in the 2D editor. If keep_margins is true, control’s position will also be updated.

Default Arguments
  • keep_margins - false

Sets [margin_left][Self::margin_left] and [margin_top][Self::margin_top] at the same time. Equivalent of changing [rect_position][Self::rect_position].

Enables whether rendering of CanvasItem based children should be clipped to this control’s rectangle. If true, parts of a child which would be visibly outside of this control’s rectangle will not be rendered.

The minimum size of the node’s bounding rectangle. If you set it to a value greater than (0, 0), the node’s bounding rectangle will always have at least this size, even if its content is smaller. If it’s set to (0, 0), the node sizes automatically to fit its content, be it a texture or child nodes.

The default cursor shape for this control. Useful for Godot plugins and applications or games that use the system’s mouse cursors. Note: On Linux, shapes may vary depending on the cursor theme of the system.

Sample code is GDScript unless otherwise noted.

Forwards the handling of this control’s drag and drop to target control. Forwarding can be implemented in the target control similar to the methods [get_drag_data][Self::get_drag_data], [can_drop_data][Self::can_drop_data], and [drop_data][Self::drop_data] but with two differences:

  1. The function name must be suffixed with _fw
  2. The function must take an extra argument that is the control doing the forwarding
extends Control
func _ready():
    set_drag_forwarding(target_control)

extends Control
func can_drop_data_fw(position, data, from_control):
    return true

func drop_data_fw(position, data, from_control):
    my_handle_data(data)

func get_drag_data_fw(position, from_control):
    set_drag_preview(my_preview)
    return my_data()

Sample code is GDScript unless otherwise noted.

Shows the given control at the mouse pointer. A good time to call this method is in [get_drag_data][Self::get_drag_data]. The control must not be in the scene tree. You should not free the control, and you should not keep a reference to the control beyond the duration of the drag. It will be deleted automatically after the drag has ended.

export (Color, RGBA) var color = Color(1, 0, 0, 1)

func get_drag_data(position):
    var cpb = ColorPickerButton.new()
    cpb.color = color
    cpb.rect_size = Vector2(50, 50)
    set_drag_preview(cpb)
    return color

Sets [margin_right][Self::margin_right] and [margin_bottom][Self::margin_bottom] at the same time.

The focus access mode for the control (None, Click or All). Only one Control can be focused at the same time, and it will receive keyboard signals.

Tells Godot which node it should give keyboard focus to if the user presses the top arrow on the keyboard or top on a gamepad by default. You can change the key by editing the ui_top input action. The node must be a Control. If this property is not set, Godot will give focus to the closest Control to the bottom of this one.

Tells Godot which node it should give keyboard focus to if the user presses Tab on a keyboard by default. You can change the key by editing the ui_focus_next input action. If this property is not set, Godot will select a “best guess” based on surrounding nodes in the scene tree.

Tells Godot which node it should give keyboard focus to if the user presses Shift+Tab on a keyboard by default. You can change the key by editing the ui_focus_prev input action. If this property is not set, Godot will select a “best guess” based on surrounding nodes in the scene tree.

Sets the [rect_global_position][Self::rect_global_position] to given position. If keep_margins is true, control’s anchors will be updated instead of margins.

Default Arguments
  • keep_margins - false

Controls the direction on the horizontal axis in which the control should grow if its horizontal minimum size is changed to be greater than its current size, as the control always has to be at least the minimum size.

Tells the parent Container nodes how they should resize and place the node on the X axis. Use one of the SizeFlags constants to change the flags. See the constants to learn what each does.

Distance between the node’s top edge and its parent control, based on [anchor_top][Self::anchor_top]. Margins are often controlled by one or multiple parent Container nodes, so you should not modify them manually if your node is a direct child of a Container. Margins update automatically when you move or resize the node.

Sets the margins to a preset from [enum Control.LayoutPreset] enum. This is the code equivalent to using the Layout menu in the 2D editor. Use parameter resize_mode with constants from [enum Control.LayoutPresetMode] to better determine the resulting size of the Control. Constant size will be ignored if used with presets that change size, e.g. PRESET_LEFT_WIDE. Use parameter margin to determine the gap between the Control and the edges.

Default Arguments
  • resize_mode - 0
  • margin - 0

Controls whether the control will be able to receive mouse button input events through [_gui_input][Self::_gui_input] and how these events should be handled. Also controls whether the control can receive the mouse_entered, and mouse_exited signals. See the constants to learn what each does.

Enables whether input should propagate when you close the control as modal. If false, stops event handling at the viewport input event handling. The viewport first hides the modal and after marks the input as handled.

By default, the node’s pivot is its top-left corner. When you change its [rect_rotation][Self::rect_rotation] or [rect_scale][Self::rect_scale], it will rotate or scale around this pivot. Set this property to [rect_size][Self::rect_size] / 2 to pivot around the Control’s center.

Sets the [rect_position][Self::rect_position] to given position. If keep_margins is true, control’s anchors will be updated instead of margins.

Default Arguments
  • keep_margins - false

Sets the rotation (in radians).

The node’s rotation around its pivot, in degrees. See [rect_pivot_offset][Self::rect_pivot_offset] to change the pivot’s position.

The node’s scale, relative to its [rect_size][Self::rect_size]. Change this property to scale the node around its [rect_pivot_offset][Self::rect_pivot_offset]. The Control’s [hint_tooltip][Self::hint_tooltip] will also scale according to this value. Note: This property is mainly intended to be used for animation purposes. Text inside the Control will look pixelated or blurry when the Control is scaled. To support multiple resolutions in your project, use an appropriate viewport stretch mode as described in the [documentation]documentation instead of scaling Controls individually. Note: If the Control node is a child of a Container node, the scale will be reset to Vector2(1, 1) when the scene is instanced. To set the Control’s scale when it’s instanced, wait for one frame using yield(get_tree(), "idle_frame") then set its [rect_scale][Self::rect_scale] property.

Sets the size (see [rect_size][Self::rect_size]). If keep_margins is true, control’s anchors will be updated instead of margins.

Default Arguments
  • keep_margins - false

If the node and at least one of its neighbours uses the SIZE_EXPAND size flag, the parent Container will let it take more or less space depending on this property. If this node has a stretch ratio of 2 and its neighbour a ratio of 1, this node will take two thirds of the available space.

Changing this property replaces the current Theme resource this node and all its Control children use.

The name of a theme type variation used by this Control to look up its own theme items. When empty, the class name of the node is used (e.g. Button for the Button control), as well as the class names of all parent classes (in order of inheritance). When set, this property gives the highest priority to the type of the specified name. This type can in turn extend another type, forming a dependency chain. See Theme.set_type_variation. If the theme item cannot be found using this type or its base types, lookup falls back on the class names. Note: To look up Control’s own items use various get_* methods without specifying theme_type. Note: Theme items are looked for in the tree order, from branch to root, where each Control node is checked for its theme property. The earliest match against any type/class name is returned. The project-level Theme and the default Theme are checked last.

Sample code is GDScript unless otherwise noted.

Changes the tooltip text. The tooltip appears when the user’s mouse cursor stays idle over this control for a few moments, provided that the mouse_filter property is not MOUSE_FILTER_IGNORE. You can change the time required for the tooltip to appear with gui/timers/tooltip_delay_sec option in Project Settings. The tooltip popup will use either a default implementation, or a custom one that you can provide by overriding [_make_custom_tooltip][Self::_make_custom_tooltip]. The default tooltip includes a PopupPanel and Label whose theme properties can be customized using Theme methods with the "TooltipPanel" and "TooltipLabel" respectively. For example:

var style_box = StyleBoxFlat.new()
style_box.set_bg_color(Color(1, 1, 0))
style_box.set_border_width_all(2)
theme.set_stylebox("panel", "TooltipPanel", style_box)
theme.set_color("font_color", "TooltipLabel", Color(0, 1, 1))

Controls the direction on the vertical axis in which the control should grow if its vertical minimum size is changed to be greater than its current size, as the control always has to be at least the minimum size.

Tells the parent Container nodes how they should resize and place the node on the Y axis. Use one of the SizeFlags constants to change the flags. See the constants to learn what each does.

Displays a control as modal. Control must be a subwindow. Modal controls capture the input signals until closed or the area outside them is accessed. When a modal control loses focus, or the ESC key is pressed, they automatically hide. Modal controls are used extensively for popup dialogs and menus. If exclusive is true, other controls will not receive input and clicking outside this control will not close it.

Default Arguments
  • exclusive - false

Moves the mouse cursor to to_position, relative to [rect_position][Self::rect_position] of this Control.

Methods from Deref<Target = CanvasItem>

Draws a unfilled arc between the given angles. The larger the value of point_count, the smoother the curve. See also draw_circle. 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 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.

Default Arguments
  • width - 1.0
  • antialiased - false

Draws a string character using a custom font. Returns the advance, depending on the character width and kerning with an optional next character.

Default Arguments
  • modulate - Color( 1, 1, 1, 1 )

Draws a colored, filled circle. See also draw_arc, draw_polyline and draw_polygon. Note: Built-in antialiasing is not provided for draw_circle. As a workaround, install the Antialiased Line2D add-on then create an AntialiasedRegularPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.

Draws a colored polygon of any amount of points, convex or concave. Unlike draw_polygon, 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 Antialiased Line2D add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.

Default Arguments
  • uvs - PoolVector2Array( )
  • texture - null
  • normal_map - null
  • antialiased - false

Draws a line from a 2D point to another, with a given color and width. It can be optionally antialiased. See also draw_multiline and draw_polyline. 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 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.

Default Arguments
  • width - 1.0
  • antialiased - false

Draws a Mesh in 2D, using the provided texture. See MeshInstance2D for related documentation.

Default Arguments
  • normal_map - null
  • transform - Transform2D( 1, 0, 0, 1, 0, 0 )
  • modulate - Color( 1, 1, 1, 1 )

Draws multiple disconnected lines with a uniform color. When drawing large amounts of lines, this is faster than using individual draw_line calls. To draw interconnected lines, use draw_polyline instead. Note: width and antialiased are currently not implemented and have no effect. As a workaround, install the 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.

Default Arguments
  • width - 1.0
  • antialiased - false

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 draw_line calls. To draw interconnected lines, use draw_polyline_colors instead. Note: width and antialiased are currently not implemented and have no effect. As a workaround, install the 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.

Default Arguments
  • width - 1.0
  • antialiased - false

Draws a MultiMesh in 2D with the provided texture. See MultiMeshInstance2D for related documentation.

Default Arguments
  • normal_map - null

Draws a solid polygon of any amount of points, convex or concave. Unlike draw_colored_polygon, each point’s color can be changed individually. See also draw_polyline and draw_polyline_colors. 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 Antialiased Line2D add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.

Default Arguments
  • uvs - PoolVector2Array( )
  • texture - null
  • normal_map - null
  • antialiased - false

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 draw_line calls. To draw disconnected lines, use draw_multiline instead. See also draw_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 Antialiased Line2D add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.

Default Arguments
  • width - 1.0
  • antialiased - false

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 draw_line calls. To draw disconnected lines, use draw_multiline_colors instead. See also draw_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 Antialiased Line2D add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.

Default Arguments
  • width - 1.0
  • antialiased - false

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 draw_line, draw_polyline, draw_polygon, and draw_rect.

Default Arguments
  • texture - null
  • width - 1.0
  • normal_map - null

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 Antialiased Line2D add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.

Default Arguments
  • filled - true
  • width - 1.0
  • antialiased - false

Sets a custom transform for drawing via components. Anything drawn afterwards will be transformed by this.

Sets a custom transform for drawing via matrix. Anything drawn afterwards will be transformed by this.

Sample code is GDScript unless otherwise noted.

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:

var default_font = Control.new().get_font("font")
draw_string(default_font, Vector2(64, 64), "Hello world")

See also Font.draw.

Default Arguments
  • modulate - Color( 1, 1, 1, 1 )
  • clip_w - -1

Draws a styled rectangle.

Draws a texture at a given position.

Default Arguments
  • modulate - Color( 1, 1, 1, 1 )
  • normal_map - null

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.

Default Arguments
  • modulate - Color( 1, 1, 1, 1 )
  • transpose - false
  • normal_map - null

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.

Default Arguments
  • modulate - Color( 1, 1, 1, 1 )
  • transpose - false
  • normal_map - null
  • clip_uv - true

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.

Returns the RID of the World2D canvas where this item is in.

Returns the canvas item RID used by VisualServer for this item.

Returns the transform matrix of this item’s canvas.

Returns the mouse’s position in the CanvasLayer that this CanvasItem is in using the coordinate system of the CanvasLayer.

Returns the global transform matrix of this item.

Returns the global transform matrix of this item in relation to the canvas.

The rendering layers in which this CanvasItem responds to Light2D nodes.

Returns the mouse’s position in this CanvasItem using the local coordinate system of this CanvasItem.

The material applied to textures on this CanvasItem.

The color applied to textures on this CanvasItem.

The color applied to textures on this CanvasItem. This is not inherited by children CanvasItems.

Returns the transform matrix of this item.

If true, the parent CanvasItem’s material property is used as this one’s material.

Returns the viewport’s boundaries as a Rect2.

Returns this item’s transform in relation to the viewport.

Returns the World2D where this item is in.

Hide the CanvasItem if it’s currently visible. This is equivalent to setting [visible][Self::visible] to false.

If true, the object draws behind its parent.

Returns true if local transform notifications are communicated to children.

Returns true if the node is set as top-level. See set_as_toplevel.

Returns true if global transform notifications are communicated to children.

If true, this CanvasItem is drawn. The node is only visible if all of its antecedents are visible as well (in other words, is_visible_in_tree must return true). Note: For controls that inherit Popup, the correct way to make them visible is to call one of the multiple popup*() functions instead.

Returns true if the node is present in the SceneTree, its [visible][Self::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, and is consequently not drawn (see [_draw][Self::_draw]).

Assigns screen_point as this node’s new local transform.

Transformations issued by event’s inputs are applied in local space instead of global space.

If enable is true, this CanvasItem will not inherit its transform from parent CanvasItems. Its draw order will also be changed to make it draw on top of other CanvasItems that are not set as top-level. The CanvasItem will effectively act as if it was placed as a child of a bare Node. See also is_set_as_toplevel.

If true, the object draws behind its parent.

The rendering layers in which this CanvasItem responds to Light2D nodes.

The material applied to textures on this CanvasItem.

The color applied to textures on this CanvasItem.

If enable is true, this node will receive NOTIFICATION_LOCAL_TRANSFORM_CHANGED when its local transform changes.

If enable is true, this node will receive NOTIFICATION_TRANSFORM_CHANGED when its global transform changes.

The color applied to textures on this CanvasItem. This is not inherited by children CanvasItems.

If true, the parent CanvasItem’s material property is used as this one’s material.

If true, this CanvasItem is drawn. The node is only visible if all of its antecedents are visible as well (in other words, is_visible_in_tree must return true). Note: For controls that inherit Popup, the correct way to make them visible is to call one of the multiple popup*() functions instead.

Show the CanvasItem if it’s currently hidden. This is equivalent to setting [visible][Self::visible] to true. For controls that inherit Popup, the correct way to make them visible is to call one of the multiple popup*() functions instead.

Queues the CanvasItem to redraw. During idle time, if CanvasItem is visible, NOTIFICATION_DRAW is sent and [_draw][Self::_draw] is called. This only occurs once per frame, even if this method has been called multiple times.

Methods from Deref<Target = Node>

source

pub const NOTIFICATION_POST_ENTER_TREE: i64 = 27i64

Sample code is GDScript unless otherwise noted.

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 remove_child 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 PackedScene, you must set owner in addition to calling add_child. This is typically relevant for tool scripts and editor plugins. If add_child 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.

Default Arguments
  • legible_unique_name - false

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.

Default Arguments
  • legible_unique_name - false

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 is_inside_tree). See notes in the description, and the group methods in SceneTree. The persistent option is used when packing node to 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.

Default Arguments
  • persistent - false

Returns true if the node can process while the scene tree is paused (see pause_mode). Always returns true if the scene tree is not paused, and false if the node is not in the tree.

Sample code is GDScript unless otherwise noted.

Creates a new SceneTreeTween and binds it to this node. This is equivalent of doing:

get_tree().create_tween().bind_node(self)

Duplicates the node, returning a new node. You can fine-tune the behavior using the flags (see DuplicateFlags). Note: It will not work properly if the node contains a script with constructor arguments (i.e. needs to supply arguments to [Object._init][Object::_init] method). In that case, the node will be duplicated without a script.

Default Arguments
  • flags - 15

Finds a descendant of this node whose name matches mask as in [String.match][GodotString::match] (i.e. case-sensitive, but "*" matches zero or more characters and "?" matches any single character except "."). Returns null if no matching 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 get_node instead. To avoid using find_node too often, consider caching the node reference into a variable.

Default Arguments
  • recursive - true
  • owned - true

Finds the first parent of the current node whose name matches mask as in [String.match][GodotString::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 get_node instead. To avoid using find_parent too often, consider caching the node reference into a variable.

Returns a child node by its index (see get_child_count). This method is often used for iterating all children of a node. To access a child node via its name, use get_node.

Returns the number of child nodes.

Returns an array of references to node’s children.

The override to the default MultiplayerAPI. Set to null to use the default SceneTree one.

If a scene is instantiated from a file, its topmost node contains the absolute file path from which it was loaded in filename (e.g. res://levels/1.tscn). Otherwise, filename is set to an empty string.

Sample code is GDScript unless otherwise noted.

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 get_groups, use the following snippet:

var non_internal_groups = []
for group in get_groups():
    if not group.begins_with("_"):
        non_internal_groups.push_back(group)

Returns the node’s index, i.e. its position among the siblings of its parent.

The MultiplayerAPI instance associated with this node. Either the custom_multiplayer, or the default SceneTree one (if inside tree).

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 add_child. When setting the name manually, any @ will be removed.

Returns the peer ID of the network master for this node. See set_network_master.

Sample code is GDScript unless otherwise noted.

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, null is returned and an error is logged. Attempts to access methods on the return value will result in an “Attempt to call on a null instance.” error. Note: Fetching absolute paths only works when the node is inside the scene tree (see is_inside_tree). 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")

Sample code is GDScript unless otherwise noted.

Fetches a node and one of its resources as specified by the NodePath’s subname (e.g. Area2D/CollisionShape2D:shape). If several nested resources are specified in the NodePath, the last one will be fetched. The return value is an array of size 3: the first index points to the Node (or null if not found), the second index points to the Resource (or null if not found), and the third index is the remaining NodePath, if any. For example, assuming that Area2D/CollisionShape2D is a valid node and that its shape property has been assigned a 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]

Similar to get_node, but does not log an error if path does not point to a valid 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 PackedScene), all the nodes it owns will be saved with it. This allows for the creation of complex SceneTrees, with instancing and subinstancing. Note: If you want a child to be persisted to a PackedScene, you must set owner in addition to calling add_child. This is typically relevant for tool scripts and editor plugins. If add_child 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.

Returns the parent node of the current node, or null if the node lacks a parent.

Returns the absolute path of the current node. This only works if the current node is inside the scene tree (see is_inside_tree).

Returns the relative NodePath from this node to the specified node. Both nodes must be in the same scene or the function will fail.

Pause mode. How the node will behave if the SceneTree is paused.

Allows enabling or disabling physics interpolation per node, offering a finer grain of control than turning physics interpolation on and off globally. Note: This can be especially useful for Cameras, where custom interpolation can sometimes give superior results.

Returns the time elapsed (in seconds) since the last physics-bound frame (see [_physics_process][Self::_physics_process]). This is always a constant value in physics processing unless the frames per second is changed via Engine.iterations_per_second.

Returns the node’s order in the scene tree branch. For example, if called on the first child node the position is 0.

Returns the time elapsed (in seconds) since the last process callback. This value may vary from frame to frame.

The node’s priority in the execution order of the enabled processing callbacks (i.e. NOTIFICATION_PROCESS, NOTIFICATION_PHYSICS_PROCESS and their internal counterparts). Nodes whose process priority value is lower will have their processing callbacks executed first.

Returns true if this is an instance load placeholder. See InstancePlaceholder.

Returns the SceneTree that contains this node.

Returns the node’s Viewport.

Returns true if the node that the NodePath points to exists.

Returns true if the NodePath points to a valid node and its subname points to a valid resource, e.g. Area2D/CollisionShape2D:shape. Properties with a non-Resource type (e.g. nodes or primitive math types) are not considered resources.

Returns true if the given node is a direct or indirect child of the current node.

Returns true if the node is folded (collapsed) in the Scene dock.

Returns true if the given node occurs later in the scene hierarchy than the current node.

Returns true if this node is in the specified group. See notes in the description, and the group methods in SceneTree.

Returns true if this node is currently inside a SceneTree.

Returns true if the local system is the master of this node.

Returns true if the physics interpolated flag is set for this Node (see physics_interpolation_mode). 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 is_physics_interpolated_and_enabled.

Returns true if physics interpolation is enabled (see physics_interpolation_mode) and enabled in the SceneTree. This is a convenience version of is_physics_interpolated that also checks whether physics interpolation is enabled globally. See [SceneTree.physics_interpolation][SceneTree::physics_interpolation] and [member ProjectSettings.physics/common/physics_interpolation].

Returns true if physics processing is enabled (see set_physics_process).

Returns true if internal physics processing is enabled (see set_physics_process_internal).

Returns true if processing is enabled (see set_process).

Returns true if the node is processing input (see set_process_input).

Returns true if internal processing is enabled (see set_process_internal).

Returns true if the node is processing unhandled input (see set_process_unhandled_input).

Returns true if the node is processing unhandled key input (see set_process_unhandled_key_input).

Sets this node’s name as a unique name in its owner. This allows the node to be accessed as %Name instead of the full path, from any node within that scene. If another node with the same owner already had that name declared as unique, that other node’s name will no longer be set as having a unique name.

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.

Prints all stray nodes (nodes outside the SceneTree). Used for debugging. Works only in debug builds.

Sample code is GDScript unless otherwise noted.

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 get_node function. Example output:

TheGame
TheGame/Menu
TheGame/Menu/Label
TheGame/Menu/Camera2D
TheGame/SplashScreen
TheGame/SplashScreen/Camera2D

Sample code is GDScript unless otherwise noted.

Similar to print_tree, 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

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.

Default Arguments
  • args - [ ]
  • parent_first - false

Notifies the current node and all its children recursively by calling Object.notification on all of them.

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 [Object.free][Object::free]. Use Object.is_queued_for_deletion 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 [method @GDScript.is_instance_valid] before attempting to call its methods or access its properties.

Moves this node to the bottom of parent node’s children hierarchy. This is often useful in GUIs (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.

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.

Removes a child node. The node is NOT deleted and must be deleted manually. Note: This function may set the owner of the removed Node (or its descendants) to be null, if that owner is no longer a parent or ancestor.

Removes a node from a group. See notes in the description, and the group methods in SceneTree.

Replaces a node in a scene by the given one. Subscriptions that pass through this node will be lost. Note: The given node will become the new parent of any child nodes that the replaced node had. Note: The replaced node is not automatically freed, so you either need to keep it in a variable for later use or free it using [Object.free][Object::free].

Default Arguments
  • keep_data - false

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 [_ready][Self::_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).

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. This glitch can be prevented by calling reset_physics_interpolation, which temporarily turns off interpolation until the physics tick is complete. NOTIFICATION_RESET_PHYSICS_INTERPOLATION will be received by the node and all children recursively. Note: This function should be called after moving the node, rather than before.

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 NodePath, including the exact same node name. Behaviour depends on the RPC configuration for the given method, see rpc_config. Methods are not exposed to RPCs by default. See also rset and rset_config for properties. Returns null. Note: You can only safely use RPCs on clients after you received the connected_to_server signal from the SceneTree. You also need to keep track of the connection state, either by the SceneTree signals like server_disconnected or by checking SceneTree.network_peer.get_connection_status() == CONNECTION_CONNECTED.

Changes the RPC mode for the given method to the given mode. See [enum 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 rset and rset_config for properties.

Sends a rpc to a specific peer identified by peer_id (see NetworkedMultiplayerPeer.set_target_peer). Returns null.

Sends a rpc using an unreliable protocol. Returns null.

Sends a rpc to a specific peer identified by peer_id using an unreliable protocol (see NetworkedMultiplayerPeer.set_target_peer). Returns null.

Remotely changes a property’s value on other peers (and locally). Behaviour depends on the RPC configuration for the given property, see rset_config. See also rpc for RPCs for methods, most information applies to this method as well.

Changes the RPC mode for the given property to the given mode. See [enum 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 rpc and rpc_config for methods.

Remotely changes the property’s value on a specific peer identified by peer_id (see NetworkedMultiplayerPeer.set_target_peer).

Remotely changes the property’s value on other peers (and locally) using an unreliable protocol.

Remotely changes property’s value on a specific peer identified by peer_id using an unreliable protocol (see NetworkedMultiplayerPeer.set_target_peer).

The override to the default MultiplayerAPI. Set to null to use the default SceneTree one.

Sets the folded state of the node in the Scene dock.

If a scene is instantiated from a file, its topmost node contains the absolute file path from which it was loaded in filename (e.g. res://levels/1.tscn). Otherwise, filename is set to an empty 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 add_child. When setting the name manually, any @ will be removed.

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.

Default Arguments
  • recursive - true

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. Note: If you want a child to be persisted to a PackedScene, you must set owner in addition to calling add_child. This is typically relevant for tool scripts and editor plugins. If add_child 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.

Pause mode. How the node will behave if the SceneTree is paused.

Allows enabling or disabling physics interpolation per node, offering a finer grain of control than turning physics interpolation on and off globally. Note: This can be especially useful for Cameras, where custom interpolation can sometimes give superior results.

Enables or disables physics (i.e. fixed framerate) processing. When a node is being processed, it will receive a NOTIFICATION_PHYSICS_PROCESS at a fixed (usually 60 FPS, see Engine.iterations_per_second to change) interval (and the [_physics_process][Self::_physics_process] callback will be called if exists). Enabled automatically if [_physics_process][Self::_physics_process] is overridden. Any calls to this before [_ready][Self::_ready] will be ignored.

Enables or disables internal physics for this node. Internal physics processing happens in isolation from the normal [_physics_process][Self::_physics_process] 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 (set_physics_process). 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.

Enables or disables processing. When a node is being processed, it will receive a NOTIFICATION_PROCESS on every drawn frame (and the [_process][Self::_process] callback will be called if exists). Enabled automatically if [_process][Self::_process] is overridden. Any calls to this before [_ready][Self::_ready] will be ignored.

Enables or disables input processing. This is not required for GUI controls! Enabled automatically if [_input][Self::_input] is overridden. Any calls to this before [_ready][Self::_ready] will be ignored.

Enables or disabled internal processing for this node. Internal processing happens in isolation from the normal [_process][Self::_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 (set_process). 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.

The node’s priority in the execution order of the enabled processing callbacks (i.e. NOTIFICATION_PROCESS, NOTIFICATION_PHYSICS_PROCESS and their internal counterparts). Nodes whose process priority value is lower will have their processing callbacks executed first.

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 Control). Enabled automatically if [_unhandled_input][Self::_unhandled_input] is overridden. Any calls to this before [_ready][Self::_ready] will be ignored.

Enables unhandled key input processing. Enabled automatically if [_unhandled_key_input][Self::_unhandled_key_input] is overridden. Any calls to this before [_ready][Self::_ready] will be ignored.

Sets whether this is an instance load placeholder. See InstancePlaceholder.

Sets this node’s name as a unique name in its owner. This allows the node to be accessed as %Name instead of the full path, from any node within that scene. If another node with the same owner already had that name declared as unique, that other node’s name will no longer be set as having a unique name.

Updates the warning displayed for this node in the Scene Dock. Use [_get_configuration_warning][Self::_get_configuration_warning] to setup the warning message to display.

Methods from Deref<Target = Object>

Adds a user-defined signal. Arguments are optional, but can be added as an Array of dictionaries, each containing name: String and type: int (see [enum Variant.Type]) entries.

Default Arguments
  • arguments - [ ]

Sample code is GDScript unless otherwise noted.

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

Safety

This function bypasses Rust’s static type checks (aliasing, thread boundaries, calls to free(), …).

Sample code is GDScript unless otherwise noted.

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

Safety

This function bypasses Rust’s static type checks (aliasing, thread boundaries, calls to free(), …).

Sample code is GDScript unless otherwise noted.

Calls the method on the object and returns the result. Contrarily to call, this method does not support a variable number of arguments but expects all parameters to be via a single Array.

callv("set", [ "position", Vector2(42.0, 0.0) ])
Safety

This function bypasses Rust’s static type checks (aliasing, thread boundaries, calls to free(), …).

Returns true if the object can translate strings. See set_message_translation and tr.

Sample code is GDScript unless otherwise noted.

Connects a signal to a method on a target object. Pass optional binds to the call as an Array of parameters. These parameters will be passed to the method after any parameter used in the call to emit_signal. Use flags to set deferred or one-shot connections. See 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 CONNECT_REFERENCE_COUNTED. To avoid this, first, use is_connected 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 connect and parameters used when calling emit_signal:

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])
Default Arguments
  • binds - [ ]
  • flags - 0

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 is_connected to ensure that the connection exists.

Sample code is GDScript unless otherwise noted.

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

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

Returns the object’s class as a String. See also is_class. Note: get_class does not take class_name declarations into account. If the object has a class_name defined, the base class name will be returned instead.

Returns an Array of dictionaries with information about signals that are connected to the object. Each 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.

Gets the object’s property indexed by the given 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 NodePath argument, it doesn’t support actual paths to Nodes in the scene tree, only colon-separated sub-property paths. For the purpose of nodes, use Node.get_node_and_resource instead.

Returns the object’s unique instance ID. This ID can be saved in EncodedObjectAsID, and can be used to retrieve the object instance with [method @GDScript.instance_from_id].

Returns the object’s metadata entry for the given name. Throws error if the entry does not exist, unless default is not null (in which case the default value will be returned).

Default Arguments
  • default - null

Returns the object’s metadata as a PoolStringArray.

Returns the object’s methods and their signatures as an Array.

Returns the object’s property list as an Array of dictionaries. Each property’s Dictionary contain at least name: String and type: int (see [enum Variant.Type]) entries. Optionally, it can also include hint: int (see [PropertyHint][PropertyHint]), hint_string: String, and usage: int (see [PropertyUsageFlags][PropertyUsageFlags]).

Returns the object’s Script instance, or null if none is assigned.

Returns an Array of connections for the given signal.

Returns the list of signals as an Array of dictionaries.

Returns true if a metadata entry is found with the given name.

Returns true if the object contains the given method.

Returns true if the given signal exists.

Returns true if the given user-defined signal exists. Only signals added using add_user_signal are taken into account.

Returns true if signal emission blocking is enabled.

Returns true if the object inherits from the given class. See also get_class. Note: is_class does not take class_name declarations into account. If the object has a class_name defined, is_class will return false for that name.

Returns true if a connection exists for a given signal, target, and method.

Returns true if the Node.queue_free method was called for the object.

Send a given notification to the object, which will also trigger a call to the [_notification][Self::_notification] method of all classes that the object inherits from. If reversed is true, [_notification][Self::_notification] is called first on the object’s own class, and then up to its successive parent classes. If reversed is false, [_notification][Self::_notification] is called first on the highest ancestor (Object itself), and then down to its successive inheriting classes.

Default Arguments
  • reversed - false

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.

Removes a given entry from the object’s metadata. See also set_meta.

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

If set to true, signal emission is blocked.

Assigns a new value to the given property, after the current frame’s physics step. This is equivalent to calling set via call_deferred, 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).

Sample code is GDScript unless otherwise noted.

Assigns a new value to the property identified by the 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)

Defines whether the object can translate strings (with calls to tr). Enabled by default.

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 remove_meta. 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".

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 [_init][Self::_init] method will be called.

Returns a String representing the object. If not overridden, defaults to "[ClassName:RID]". Override the method [_to_string][Self::_to_string] to customize the String representation.

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 set_message_translation.

Trait Implementations

Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
The memory management kind of this type. This modifies the behavior of the Ref smart pointer. See its type-level documentation for more information. Read more
Creates an explicitly null reference of Self as a method argument. This makes type inference easier for the compiler compared to Option. Read more
Creates a new instance of Self using a zero-argument constructor, as a Unique reference. Read more
Performs a dynamic reference downcast to target type. Read more
Performs a static reference upcast to a supertype that is guaranteed to be valid. Read more
Creates a persistent reference to the same Godot object with shared thread access. Read more
Creates a persistent reference to the same Godot object with unique access. Read more
Recovers a instance ID previously returned by Object::get_instance_id if the object is still alive. See also TRef::try_from_instance_id. Read more
Recovers a instance ID previously returned by Object::get_instance_id if the object is still alive, and panics otherwise. This does NOT guarantee that the resulting reference is safe to use. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Convenience method to obtain a reference to a node at path relative to self, and cast it to the desired type. Returns None if the node does not exist or is not of the correct type. Read more
Convenience method to obtain a reference to a node at path relative to self, and cast it to an instance of the desired NativeClass type. Returns None if the node does not exist or is not of the correct type. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.