| Parameter | Description |
|---|---|
| variable | Variable to reference. Must belong to this graph. |
| position | Position of the node on the graph canvas. |
IVariableNode The newly created variable node.
Creates and adds a new variable node referencing an existing variable.
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.
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.
| Parameter | Description |
|---|---|
| variable | Variable to reference. Must belong to this graph. |
| position | Position of the node on the graph canvas. |
| mode | Mode of the variable node. |
IVariableNode The newly created variable node.
Creates and adds a new variable node with the specified mode, referencing an existing variable.
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.
// 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.