Skip to content
Download
API reference

ProceduralGraph

Inherits: Resource < Shared < Object

A graph of procedural nodes, saved as a resource.

Nodes (ProceduralNode) wired from output pins to input pins. Only what reaches a ProceduralNodeOutput runs. Parameters (set_parameter()) can drive node settings (bind_parameter()), so the same graph makes a dense forest or a sparse one.

graph : ProceduralGraph = ProceduralGraph.new()
sampler : int = graph.add_node(ProceduralNodeAreaSampler.new())
output : int = graph.add_node(ProceduralNodeOutput.new())
graph.connect_nodes(sampler, &"Out", output, &"In")
TypeNameDefault
floatdefault_grid_size0.0
ReturnsMethod
intadd_comment(text, rect, nodes, id)
intadd_node(node, position, id)
Errorbind_parameter(node, property, parameter)
intcollapse_to_subgraph(ids)
Errorconnect_nodes(from, from_port, to, to_port)
voiddisconnect_nodes(from, from_port, to, to_port)
StringNameget_bound_parameter(node, property)
Colorget_comment_color(id)
[]i32get_comment_ids()
[]i32get_comment_nodes(id)
intget_comment_of_node(node)
Rect2get_comment_rect(id)
Stringget_comment_text(id)
[]Dictionaryget_connections()
intget_content_hash()
ProceduralNodeget_node(id)
intget_node_count()
[]i32get_node_ids()
Vector2get_node_position(id)
Variantget_parameter(name)
[]Stringget_parameter_names()
Dictionaryget_state()
boolhas_comment(id)
boolhas_node(id)
boolhas_parameter(name)
boolis_node_connected(from, from_port, to, to_port)
voidremove_comment(id)
voidremove_node(id)
voidremove_parameter(name)
voidset_comment_color(id, color)
voidset_comment_nodes(id, nodes)
voidset_comment_rect(id, rect)
voidset_comment_text(id, text)
voidset_node_position(id, position)
voidset_parameter(name, value)
voidset_state(state)
voidunbind_parameter(node, property)

comments_changed()

Emitted when its comments change. Not Resource.changed: comments don’t make anything again.

float default_grid_size = 0.0

Setter/getter: set_default_grid_size(), get_default_grid_size()

In a world generated in cells, the cells that the nodes getting nothing from others (and so the nodes after them) run for; see ProceduralNodeGridSize. 0: each cell.

int add_comment(text: String, rect: Rect2, nodes: []i32 = PackedInt32Array(), id: int = 0)

Adds a comment box with text at rect (in the graph’s coordinates) around the nodes nodes (they move with it in the editor; a node leaves the comment it was in). Returns its id (id when given). Comments do not change what the graph makes, nor get_content_hash().

int add_node(node: ProceduralNode, position: Vector2 = Vector2(0, 0), id: int = 0)

Adds a node and returns its id (or uses id when it is free). position is where the graph editor shows it.

Error bind_parameter(node: int, property: StringName, parameter: StringName)

In every run, the setting property of the node node takes the value of parameter (the run’s, or the default).

int collapse_to_subgraph(ids: []i32)

Moves the nodes ids into a new ProceduralNodeSubgraph with an embedded graph, where they were: each wire that went in becomes an input pin (an Input node inside, In, In2…), each pin that fed the outside an output pin. Settings bound to parameters keep them (the inner graph gets the parameters, and a run’s value reaches them by name). Returns the Subgraph node’s id, or 0 when they can’t go (the graph’s own Input and Output nodes stay outside). The editor’s Collapse to Subgraph does this.

Error connect_nodes(from: int, from_port: StringName, to: int, to_port: StringName)

Wires from_port of from to to_port of to. Fails if the pins don’t exist, take different data, or the wire would make a loop.

void disconnect_nodes(from: int, from_port: StringName, to: int, to_port: StringName)

Removes that wire.

StringName get_bound_parameter(node: int, property: StringName) const

The parameter bound to that setting, or an empty name.

Color get_comment_color(id: int) const

The color of comment id.

[]i32 get_comment_ids() const

The ids of its comments.

[]i32 get_comment_nodes(id: int) const

The nodes in comment id.

int get_comment_of_node(node: int) const

The comment node node is in, 0 when it is in none.

Rect2 get_comment_rect(id: int) const

Where comment id is and how big it is.

String get_comment_text(id: int) const

The text of comment id.

[]Dictionary get_connections() const

The wires, as dictionaries with from_node, from_port, to_node and to_port.

int get_content_hash() const

The same for two graphs that generate the same (positions in the editor don’t count). Online uses it to check every machine has the same graph. Prefabs, textures, meshes and scripts of their own file count by their path, so the editor and the exported game agree (they are converted when the game is exported); curves, gradients, noises, biomes and subgraphs count by what they hold.

ProceduralNode get_node(id: int) const

The node with that id.

int get_node_count() const

How many nodes the graph has.

[]i32 get_node_ids() const

The ids of the nodes, in the order they were added.

Vector2 get_node_position(id: int) const

Where the graph editor shows the node.

Variant get_parameter(name: StringName) const

The default value of a parameter.

[]String get_parameter_names() const

The names of the parameters.

Dictionary get_state() const

Everything it holds, as a dictionary (its nodes are shared, not copied): with set_state(), to undo a change of the whole graph.

bool has_comment(id: int) const

Whether there is a comment id.

bool has_node(id: int) const

Whether there is a node with that id.

bool has_parameter(name: StringName) const

Whether the graph has that parameter.

bool is_node_connected(from: int, from_port: StringName, to: int, to_port: StringName) const

Whether that wire exists.

void remove_comment(id: int)

Removes the comment id (its nodes stay).

void remove_node(id: int)

Removes a node and its wires.

void remove_parameter(name: StringName)

Removes a parameter and the settings bound to it.

void set_comment_color(id: int, color: Color)

Sets the color of comment id.

void set_comment_nodes(id: int, nodes: []i32)

Puts the nodes nodes in comment id (only them); each leaves the comment it was in.

void set_comment_rect(id: int, rect: Rect2)

Sets where comment id is and how big it is (in the editor a comment with nodes fits around them).

void set_comment_text(id: int, text: String)

Sets the text of comment id.

void set_node_position(id: int, position: Vector2)

Where the graph editor shows the node.

void set_parameter(name: StringName, value: Variant)

Makes the parameter name, or changes its default value.

void set_state(state: Dictionary)

Puts back everything get_state() gave: nodes, positions, wires, parameters and bindings.

void unbind_parameter(node: int, property: StringName)

The setting keeps its own value again.