Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


AddVariableNode

Creates and adds a new variable node referencing an existing variable.
Read time 2 minutesLast updated 6 days ago

Definition

AddVariableNode(IVariable, Vector2)

Creates and adds a new variable node referencing an existing variable.
public IVariableNode AddVariableNode(IVariable variable, Vector2 position)

Parameters

variable

Variable to reference. Must belong to this graph.

position

Position of the node on the graph canvas.

Returns

Type

Description

IVariableNodeThe newly created variable node.

Remarks

The created node is in VariableNodeMode.Get mode. To create a node that can write to the variable, use Graph.AddVariableNode and pass VariableNodeMode.Set. Set mode is only available for variables of kind VariableKind.Local.
Enclose this method with Graph.UndoBeginRecordGraph and Graph.UndoEndRecordGraph to add this operation to the undo stack and to update the graph view with the changes.

Examples

IVariable health = graph.CreateVariable<int>("Health");graph.UndoBeginRecordGraph("Add Variable Node");IVariableNode node = graph.AddVariableNode(health, new Vector2(100, 100));graph.UndoEndRecordGraph();// node.Mode == VariableNodeMode.Get// Health is a local variable, so the node has an output port that provides its current value.

AddVariableNode(IVariable, Vector2, VariableNodeMode)

Creates and adds a new variable node with the specified mode, referencing an existing variable.
public IVariableNode AddVariableNode(IVariable variable, Vector2 position, VariableNodeMode mode)

Parameters

variable

Variable to reference. Must belong to this graph.

position

Position of the node on the graph canvas.

Mode of the variable node.

Returns

Type

Description

IVariableNodeThe newly created variable node.

Remarks

The
mode
parameter determines the ports the node exposes. Refer to VariableNodeMode for details. VariableNodeMode.Set is only supported for variables of kind VariableKind.Local.
To change the mode of an existing variable node, use the Allow to set value in graph checkbox in the node's inspector.
Enclose this method with Graph.UndoBeginRecordGraph and Graph.UndoEndRecordGraph to add this operation to the undo stack and to update the graph view with the changes.

Examples

// Local variables support both Get and Set modes.IVariable speed = graph.CreateVariable<float>("Speed");graph.UndoBeginRecordGraph("Add Set Variable Node");IVariableNode setNode = graph.AddVariableNode(speed, new Vector2(100, 100), VariableNodeMode.Set);graph.UndoEndRecordGraph();// setNode.Mode == VariableNodeMode.Set// The node has an extra input port for writing the value of Speed in the graph.