Skip to content

VisualShaderGroup

Inherits: Resource < RefCounted < Object

A reusable group of VisualShaderNodes similar to a function in programming.

A VisualShaderGroup encapsulates a graph of VisualShaderNodes into a reusable component. It defines its own input and output ports, which become the interface when the group is used as a VisualShaderNodeGroup node inside a VisualShader or another VisualShaderGroup.

Since an actual shader function is created for each VisualShaderGroup, you can only use global built-in variables. Parameter and Varying related nodes are not allowed.

If the group contains nodes that are incompatible with the shader context it is used in (e.g. particle nodes in a spatial shader), the group’s outputs will silently fall back to default values.

Type Name Default
String group_name "NodeGroup"
int input_port_count 0
String input_port_{index}/name ""
int input_port_{index}/type 0
int output_port_count 0
String output_port_{index}/name ""
int output_port_{index}/type 0
Returns Method
void add_node(node: VisualShaderNode, position: Vector2, id: int)
void attach_node_to_frame(id: int, frame: int)
bool can_connect_nodes(from_node: int, from_port: int, to_node: int, to_port: int) const
Error connect_nodes(from_node: int, from_port: int, to_node: int, to_port: int)
void connect_nodes_forced(from_node: int, from_port: int, to_node: int, to_port: int)
void detach_node_from_frame(id: int)
void disconnect_nodes(from_node: int, from_port: int, to_node: int, to_port: int)
String get_input_port_name(id: int) const
VisualShaderNode.PortType get_input_port_type(id: int) const
VisualShaderNode get_node(id: int) const
Array[Dictionary] get_node_connections() const
PackedInt32Array get_node_list() const
Vector2 get_node_position(id: int) const
String get_output_port_name(id: int) const
VisualShaderNode.PortType get_output_port_type(id: int) const
int get_valid_node_id() const
String insert_input_port(id: int, type: VisualShaderNode.PortType, name: String)
String insert_output_port(id: int, type: VisualShaderNode.PortType, name: String)
bool is_node_connection(from_node: int, from_port: int, to_node: int, to_port: int) const
void move_input_port(from: int, to: int)
void move_output_port(from: int, to: int)
void remove_input_port(id: int)
void remove_node(id: int)
void remove_output_port(id: int)
void replace_node(id: int, new_class: StringName)
void set_input_port_name(id: int, name: String)
void set_input_port_type(id: int, type: VisualShaderNode.PortType)
void set_node_position(id: int, position: Vector2)
void set_output_port_name(id: int, name: String)
void set_output_port_type(id: int, type: VisualShaderNode.PortType)

group_name

String group_name = "NodeGroup"

The display name of this group. This name is shown as the caption of the VisualShaderNodeGroup node in the editor.

input_port_count

int input_port_count = 0

The number of input ports defined for this group. Shrinking the array removes the trailing ports along with any connections made to them.

input_port_{index}/name

String input_port_{index}/name = ""

The name of the input port at index. It’s used as a parameter name in the generated shader function, so it’s converted into a valid identifier and made unique within the group.

input_port_{index}/type

int input_port_{index}/type = 0

The VisualShaderNode.PortType of the input port at index.

output_port_count

int output_port_count = 0

The number of output ports defined for this group. Shrinking the array removes the trailing ports along with any connections made to them.

output_port_{index}/name

String output_port_{index}/name = ""

The name of the output port at index. It’s used as a parameter name in the generated shader function, so it’s converted into a valid identifier and made unique within the group.

output_port_{index}/type

int output_port_{index}/type = 0

The VisualShaderNode.PortType of the output port at index.

add_node

void add_node(node: VisualShaderNode, position: Vector2, id: int)

Adds the specified node to the group.

attach_node_to_frame

void attach_node_to_frame(id: int, frame: int)

Attaches the given node to the given frame.

can_connect_nodes

bool can_connect_nodes(from_node: int, from_port: int, to_node: int, to_port: int) const

Returns true if the specified nodes and ports can be connected.

connect_nodes

Error connect_nodes(from_node: int, from_port: int, to_node: int, to_port: int)

Connects the specified nodes and ports.

connect_nodes_forced

void connect_nodes_forced(from_node: int, from_port: int, to_node: int, to_port: int)

Connects the specified nodes and ports, even if they can’t be connected.

detach_node_from_frame

void detach_node_from_frame(id: int)

Detaches the given node from the frame it is attached to.

disconnect_nodes

void disconnect_nodes(from_node: int, from_port: int, to_node: int, to_port: int)

Disconnects the specified nodes and ports.

get_input_port_name

String get_input_port_name(id: int) const

Returns the name of the input port at the given id.

get_input_port_type

VisualShaderNode.PortType get_input_port_type(id: int) const

Returns the type of the input port at the given id.

get_node

VisualShaderNode get_node(id: int) const

Returns the shader node instance with the specified id.

get_node_connections

Array[Dictionary] get_node_connections() const

Returns the list of connected nodes.

get_node_list

PackedInt32Array get_node_list() const

Returns the list of all nodes in the group.

get_node_position

Vector2 get_node_position(id: int) const

Returns the position of the specified node within the shader graph.

get_output_port_name

String get_output_port_name(id: int) const

Returns the name of the output port at the given id.

get_output_port_type

VisualShaderNode.PortType get_output_port_type(id: int) const

Returns the type of the output port at the given id.

get_valid_node_id

int get_valid_node_id() const

Returns the next valid node ID that can be added to the shader graph.

insert_input_port

String insert_input_port(id: int, type: VisualShaderNode.PortType, name: String)

Inserts an input port at the given id with the specified type and name.

Returns the validated port name, which may differ from name if a port with the same name already exists. Port names must be unique across both input and output ports.

insert_output_port

String insert_output_port(id: int, type: VisualShaderNode.PortType, name: String)

Inserts an output port at the given id with the specified type and name.

Returns the validated port name, which may differ from name if a port with the same name already exists. Port names must be unique across both input and output ports.

is_node_connection

bool is_node_connection(from_node: int, from_port: int, to_node: int, to_port: int) const

Returns true if the specified node and port connection exists.

move_input_port

void move_input_port(from: int, to: int)

Moves the input port at index from to index to. Connections from input nodes inside the group will be updated accordingly.

move_output_port

void move_output_port(from: int, to: int)

Moves the output port at index from to index to. Connections to output nodes inside the group will be updated accordingly.

remove_input_port

void remove_input_port(id: int)

Removes the input port at the given id.

remove_node

void remove_node(id: int)

Removes the specified node from the group.

remove_output_port

void remove_output_port(id: int)

Removes the output port at the given id.

replace_node

void replace_node(id: int, new_class: StringName)

Replaces the specified node with a node of the new class type.

set_input_port_name

void set_input_port_name(id: int, name: String)

Sets the name of the input port at the given id.

set_input_port_type

void set_input_port_type(id: int, type: VisualShaderNode.PortType)

Sets the type of the input port at the given id.

set_node_position

void set_node_position(id: int, position: Vector2)

Sets the position of the specified node.

set_output_port_name

void set_output_port_name(id: int, name: String)

Sets the name of the output port at the given id.

set_output_port_type

void set_output_port_type(id: int, type: VisualShaderNode.PortType)

Sets the type of the output port at the given id.