Up to date

This page is up to date for Godot 4.0. If you still find outdated information, please open an issue.

GraphNode

Inherits: Container < Control < CanvasItem < Node < Object

A container with connection ports, representing a node in a GraphEdit.

Description

GraphNode allows to create nodes for a GraphEdit graph with customizable content based on its child controls. GraphNode is derived from Container and it is responsible for placing its children on screen. This works similar to VBoxContainer. Children, in turn, provide GraphNode with so-called slots, each of which can have a connection port on either side.

Each GraphNode slot is defined by its index and can provide the node with up to two ports: one on the left, and one on the right. By convention the left port is also referred to as the input port and the right port is referred to as the output port. Each port can be enabled and configured individually, using different type and color. The type is an arbitrary value that you can define using your own considerations. The parent GraphEdit will receive this information on each connect and disconnect request.

Slots can be configured in the Inspector dock once you add at least one child Control. The properties are grouped by each slot's index in the "Slot" section.

Note: While GraphNode is set up using slots and slot indices, connections are made between the ports which are enabled. Because of that, GraphEdit uses the port's index and not the slot's index. You can use get_connection_input_slot and get_connection_output_slot to get the slot index from the port index.

Properties

bool

comment

false

bool

draggable

true

String

language

""

MouseFilter

mouse_filter

0 (overrides Control)

Overlay

overlay

0

Vector2

position_offset

Vector2(0, 0)

bool

resizable

false

bool

selectable

true

bool

selected

false

bool

show_close

false

TextDirection

text_direction

0

String

title

""

Methods

void

clear_all_slots ( )

void

clear_slot ( int slot_index )

Color

get_connection_input_color ( int port )

int

get_connection_input_count ( )

int

get_connection_input_height ( int port )

Vector2

get_connection_input_position ( int port )

int

get_connection_input_slot ( int port )

int

get_connection_input_type ( int port )

Color

get_connection_output_color ( int port )

int

get_connection_output_count ( )

int

get_connection_output_height ( int port )

Vector2

get_connection_output_position ( int port )

int

get_connection_output_slot ( int port )

int

get_connection_output_type ( int port )

Color

get_slot_color_left ( int slot_index ) const

Color

get_slot_color_right ( int slot_index ) const

int

get_slot_type_left ( int slot_index ) const

int

get_slot_type_right ( int slot_index ) const

bool

is_slot_draw_stylebox ( int slot_index ) const

bool

is_slot_enabled_left ( int slot_index ) const

bool

is_slot_enabled_right ( int slot_index ) const

void

set_slot ( int slot_index, bool enable_left_port, int type_left, Color color_left, bool enable_right_port, int type_right, Color color_right, Texture2D custom_icon_left=null, Texture2D custom_icon_right=null, bool draw_stylebox=true )

void

set_slot_color_left ( int slot_index, Color color )

void

set_slot_color_right ( int slot_index, Color color )

void

set_slot_draw_stylebox ( int slot_index, bool enable )

void

set_slot_enabled_left ( int slot_index, bool enable )

void

set_slot_enabled_right ( int slot_index, bool enable )

void

set_slot_type_left ( int slot_index, int type )

void

set_slot_type_right ( int slot_index, int type )

Theme Properties

Color

close_color

Color(0.875, 0.875, 0.875, 1)

Color

resizer_color

Color(0.875, 0.875, 0.875, 1)

Color

title_color

Color(0.875, 0.875, 0.875, 1)

int

close_h_offset

12

int

close_offset

22

int

port_offset

0

int

separation

2

int

title_h_offset

0

int

title_offset

26

Font

title_font

Texture2D

close

Texture2D

port

Texture2D

resizer

StyleBox

breakpoint

StyleBox

comment

StyleBox

comment_focus

StyleBox

frame

StyleBox

position

StyleBox

selected_frame

StyleBox

slot


Signals

close_request ( )

Emitted when the GraphNode is requested to be closed. Happens on clicking the close button (see show_close).


dragged ( Vector2 from, Vector2 to )

Emitted when the GraphNode is dragged.


node_deselected ( )

Emitted when the GraphNode is deselected.


node_selected ( )

Emitted when the GraphNode is selected.


position_offset_changed ( )

Emitted when the GraphNode is moved.


raise_request ( )

Emitted when the GraphNode is requested to be displayed over other ones. Happens on focusing (clicking into) the GraphNode.


resize_request ( Vector2 new_minsize )

Emitted when the GraphNode is requested to be resized. Happens on dragging the resizer handle (see resizable).


slot_updated ( int idx )

Emitted when any GraphNode's slot is updated.


Enumerations

enum Overlay:

Overlay OVERLAY_DISABLED = 0

No overlay is shown.

Overlay OVERLAY_BREAKPOINT = 1

Show overlay set in the breakpoint theme property.

Overlay OVERLAY_POSITION = 2

Show overlay set in the position theme property.


Property Descriptions

bool comment = false

  • void set_comment ( bool value )

  • bool is_comment ( )

If true, the GraphNode is a comment node.


bool draggable = true

  • void set_draggable ( bool value )

  • bool is_draggable ( )

If true, the user can drag the GraphNode.


String language = ""

  • void set_language ( String value )

  • String get_language ( )

Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.


Overlay overlay = 0

Sets the overlay shown above the GraphNode. See Overlay.


Vector2 position_offset = Vector2(0, 0)

  • void set_position_offset ( Vector2 value )

  • Vector2 get_position_offset ( )

The offset of the GraphNode, relative to the scroll offset of the GraphEdit.

Note: You cannot use position offset directly, as GraphEdit is a Container.


bool resizable = false

  • void set_resizable ( bool value )

  • bool is_resizable ( )

If true, the user can resize the GraphNode.

Note: Dragging the handle will only emit the resize_request signal, the GraphNode needs to be resized manually.


bool selectable = true

  • void set_selectable ( bool value )

  • bool is_selectable ( )

If true, the user can select the GraphNode.


bool selected = false

  • void set_selected ( bool value )

  • bool is_selected ( )

If true, the GraphNode is selected.


bool show_close = false

  • void set_show_close_button ( bool value )

  • bool is_close_button_visible ( )

If true, the close button will be visible.

Note: Pressing it will only emit the close_request signal, the GraphNode needs to be removed manually.


TextDirection text_direction = 0

Base text writing direction.


String title = ""

The text displayed in the GraphNode's title bar.


Method Descriptions

void clear_all_slots ( )

Disables all input and output slots of the GraphNode.


void clear_slot ( int slot_index )

Disables input and output slot whose index is slot_index.


Color get_connection_input_color ( int port )

Returns the Color of the input connection port.


int get_connection_input_count ( )

Returns the number of enabled input slots (connections) to the GraphNode.


int get_connection_input_height ( int port )

Returns the height of the input connection port.


Vector2 get_connection_input_position ( int port )

Returns the position of the input connection port.


int get_connection_input_slot ( int port )

Returns the corresponding slot index of the input connection port.


int get_connection_input_type ( int port )

Returns the type of the input connection port.


Color get_connection_output_color ( int port )

Returns the Color of the output connection port.


int get_connection_output_count ( )

Returns the number of enabled output slots (connections) of the GraphNode.


int get_connection_output_height ( int port )

Returns the height of the output connection port.


Vector2 get_connection_output_position ( int port )

Returns the position of the output connection port.


int get_connection_output_slot ( int port )

Returns the corresponding slot index of the output connection port.


int get_connection_output_type ( int port )

Returns the type of the output connection port.


Color get_slot_color_left ( int slot_index ) const

Returns the left (input) Color of the slot slot_index.


Color get_slot_color_right ( int slot_index ) const

Returns the right (output) Color of the slot slot_index.


int get_slot_type_left ( int slot_index ) const

Returns the left (input) type of the slot slot_index.


int get_slot_type_right ( int slot_index ) const

Returns the right (output) type of the slot slot_index.


bool is_slot_draw_stylebox ( int slot_index ) const

Returns true if the background StyleBox of the slot slot_index is drawn.


bool is_slot_enabled_left ( int slot_index ) const

Returns true if left (input) side of the slot slot_index is enabled.


bool is_slot_enabled_right ( int slot_index ) const

Returns true if right (output) side of the slot slot_index is enabled.


void set_slot ( int slot_index, bool enable_left_port, int type_left, Color color_left, bool enable_right_port, int type_right, Color color_right, Texture2D custom_icon_left=null, Texture2D custom_icon_right=null, bool draw_stylebox=true )

Sets properties of the slot with the slot_index index.

If enable_left_port/enable_right_port is true, a port will appear and the slot will be able to be connected from this side.

With type_left/type_right an arbitrary type can be assigned to each port. Two ports can be connected if they share the same type, or if the connection between their types is allowed in the parent GraphEdit (see GraphEdit.add_valid_connection_type). Keep in mind that the GraphEdit has the final say in accepting the connection. Type compatibility simply allows the GraphEdit.connection_request signal to be emitted.

Ports can be further customized using color_left/color_right and custom_icon_left/custom_icon_right. The color parameter adds a tint to the icon. The custom icon can be used to override the default port dot.

Additionally, draw_stylebox can be used to enable or disable drawing of the background stylebox for each slot. See slot.

Individual properties can also be set using one of the set_slot_* methods.

Note: This method only sets properties of the slot. To create the slot itself, add a Control-derived child to the GraphNode.


void set_slot_color_left ( int slot_index, Color color )

Sets the Color of the left (input) side of the slot slot_index to color.


void set_slot_color_right ( int slot_index, Color color )

Sets the Color of the right (output) side of the slot slot_index to color.


void set_slot_draw_stylebox ( int slot_index, bool enable )

Toggles the background StyleBox of the slot slot_index.


void set_slot_enabled_left ( int slot_index, bool enable )

Toggles the left (input) side of the slot slot_index. If enable is true, a port will appear on the left side and the slot will be able to be connected from this side.


void set_slot_enabled_right ( int slot_index, bool enable )

Toggles the right (output) side of the slot slot_index. If enable is true, a port will appear on the right side and the slot will be able to be connected from this side.


void set_slot_type_left ( int slot_index, int type )

Sets the left (input) type of the slot slot_index to type. If the value is negative, all connections will be disallowed to be created via user inputs.


void set_slot_type_right ( int slot_index, int type )

Sets the right (output) type of the slot slot_index to type. If the value is negative, all connections will be disallowed to be created via user inputs.


Theme Property Descriptions

Color close_color = Color(0.875, 0.875, 0.875, 1)

The color modulation applied to the close button icon.


Color resizer_color = Color(0.875, 0.875, 0.875, 1)

The color modulation applied to the resizer icon.


Color title_color = Color(0.875, 0.875, 0.875, 1)

Color of the title text.


int close_h_offset = 12

There is currently no description for this theme property. Please help us by contributing one!


int close_offset = 22

The vertical offset of the close button.


int port_offset = 0

Horizontal offset for the ports.


int separation = 2

The vertical distance between ports.


int title_h_offset = 0

Horizontal offset of the title text.


int title_offset = 26

Vertical offset of the title text.


Font title_font

Font used for the title text.


Texture2D close

The icon for the close button, visible when show_close is enabled.


Texture2D port

The icon used for representing ports.


Texture2D resizer

The icon used for resizer, visible when resizable is enabled.


StyleBox breakpoint

The background used when overlay is set to OVERLAY_BREAKPOINT.


StyleBox comment

The StyleBox used when comment is enabled.


StyleBox comment_focus

The StyleBox used when comment is enabled and the GraphNode is focused.


StyleBox frame

The default background for GraphNode.


StyleBox position

The background used when overlay is set to OVERLAY_POSITION.


StyleBox selected_frame

The background used when the GraphNode is selected.


StyleBox slot

The StyleBox used for each slot of the GraphNode.