ProceduralGraph
Inherits: Resource < Shared < Object
A graph of procedural nodes, saved as a resource.
Description
Section titled “Description”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")Properties
Section titled “Properties”| Type | Name | Default |
|---|---|---|
| float | default_grid_size | 0.0 |
Methods
Section titled “Methods”Signals
Section titled “Signals”comments_changed
Section titled “comments_changed”comments_changed()Emitted when its comments change. Not Resource.changed: comments don’t make anything again.
Property descriptions
Section titled “Property descriptions”default_grid_size
Section titled “default_grid_size”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.
Method descriptions
Section titled “Method descriptions”add_comment
Section titled “add_comment”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().
add_node
Section titled “add_node”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.
bind_parameter
Section titled “bind_parameter”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).
collapse_to_subgraph
Section titled “collapse_to_subgraph”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.
connect_nodes
Section titled “connect_nodes”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.
disconnect_nodes
Section titled “disconnect_nodes”void disconnect_nodes(from: int, from_port: StringName, to: int, to_port: StringName)
Removes that wire.
get_bound_parameter
Section titled “get_bound_parameter”StringName get_bound_parameter(node: int, property: StringName) const
The parameter bound to that setting, or an empty name.
get_comment_color
Section titled “get_comment_color”Color get_comment_color(id: int) const
The color of comment id.
get_comment_ids
Section titled “get_comment_ids”[]i32 get_comment_ids() const
The ids of its comments.
get_comment_nodes
Section titled “get_comment_nodes”[]i32 get_comment_nodes(id: int) const
The nodes in comment id.
get_comment_of_node
Section titled “get_comment_of_node”int get_comment_of_node(node: int) const
The comment node node is in, 0 when it is in none.
get_comment_rect
Section titled “get_comment_rect”Rect2 get_comment_rect(id: int) const
Where comment id is and how big it is.
get_comment_text
Section titled “get_comment_text”String get_comment_text(id: int) const
The text of comment id.
get_connections
Section titled “get_connections”[]Dictionary get_connections() const
The wires, as dictionaries with from_node, from_port, to_node and to_port.
get_content_hash
Section titled “get_content_hash”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.
get_node
Section titled “get_node”ProceduralNode get_node(id: int) const
The node with that id.
get_node_count
Section titled “get_node_count”int get_node_count() const
How many nodes the graph has.
get_node_ids
Section titled “get_node_ids”[]i32 get_node_ids() const
The ids of the nodes, in the order they were added.
get_node_position
Section titled “get_node_position”Vector2 get_node_position(id: int) const
Where the graph editor shows the node.
get_parameter
Section titled “get_parameter”Variant get_parameter(name: StringName) const
The default value of a parameter.
get_parameter_names
Section titled “get_parameter_names”[]String get_parameter_names() const
The names of the parameters.
get_state
Section titled “get_state”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.
has_comment
Section titled “has_comment”bool has_comment(id: int) const
Whether there is a comment id.
has_node
Section titled “has_node”Whether there is a node with that id.
has_parameter
Section titled “has_parameter”bool has_parameter(name: StringName) const
Whether the graph has that parameter.
is_node_connected
Section titled “is_node_connected”bool is_node_connected(from: int, from_port: StringName, to: int, to_port: StringName) const
Whether that wire exists.
remove_comment
Section titled “remove_comment”void remove_comment(id: int)
Removes the comment id (its nodes stay).
remove_node
Section titled “remove_node”void remove_node(id: int)
Removes a node and its wires.
remove_parameter
Section titled “remove_parameter”void remove_parameter(name: StringName)
Removes a parameter and the settings bound to it.
set_comment_color
Section titled “set_comment_color”void set_comment_color(id: int, color: Color)
Sets the color of comment id.
set_comment_nodes
Section titled “set_comment_nodes”void set_comment_nodes(id: int, nodes: []i32)
Puts the nodes nodes in comment id (only them); each leaves the comment it was in.
set_comment_rect
Section titled “set_comment_rect”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).
set_comment_text
Section titled “set_comment_text”void set_comment_text(id: int, text: String)
Sets the text of comment id.
set_node_position
Section titled “set_node_position”void set_node_position(id: int, position: Vector2)
Where the graph editor shows the node.
set_parameter
Section titled “set_parameter”void set_parameter(name: StringName, value: Variant)
Makes the parameter name, or changes its default value.
set_state
Section titled “set_state”void set_state(state: Dictionary)
Puts back everything get_state() gave: nodes, positions, wires, parameters and bindings.
unbind_parameter
Section titled “unbind_parameter”void unbind_parameter(node: int, property: StringName)
The setting keeps its own value again.