CreateVariable
Creates and adds a new variable to the graph.
Read time 1 minuteLast updated 6 days ago
Definition
- Type: Method
- Namespace: Unity.GraphToolkit.Editor
- Assembly: UnityEditor
CreateVariable(string, Type, Object, VariableKind)
Creates and adds a new variable to the graph.
public IVariable CreateVariable(string name, Type valueType, object defaultValue = null, VariableKind kind = VariableKind.Local)
Parameters
The name of the variable.
The data type of the variable.
The default value. Must be compatible with and work with Unity serialization rules for SerializeField.
valueTypeThe kind of variable, defined by VariableKind.
Returns
Type | Description |
|---|---|
| IVariable | The newly created variable. |
Remarks
If successful, also adds the node's type to the graph's list of supported types. 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.
CreateVariable<T>(string, T, VariableKind)
Creates and adds a new variable to the graph.
public IVariable CreateVariable<T>(string name, T defaultValue = default, VariableKind kind = VariableKind.Local)
Parameters
The name of the variable.
The default value. Must be compatible with and work with Unity serialization rules for SerializeField.
TThe kind of variable, defined by VariableKind.
Returns
Type | Description |
|---|---|
| IVariable | The newly created variable. |
Remarks
If successful, also adds the variable's type to the graph's list of supported types. 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.