Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

Graph.AddVariableNode

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public IVariableNode AddVariableNode(IVariable variable, Vector2 position);

Parameters

Parameter Description
variable Variable to reference. Must belong to this graph.
position Position of the node on the graph canvas.

Returns

IVariableNode The newly created variable node.

Description

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.

Declaration

public IVariableNode AddVariableNode(IVariable variable, Vector2 position, VariableNodeMode mode);

Parameters

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.

Returns

IVariableNode The newly created variable node.

Description

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.