Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


CreateVariable

Creates and adds a new variable to the state machine.
Read time 1 minuteLast updated 6 days ago

Definition

CreateVariable(string, Type, Object, VariableKind)

Creates and adds a new variable to the state machine.
public IVariable CreateVariable(string name, Type valueType, object defaultValue = null, VariableKind kind = VariableKind.Local)

Parameters

name

The name of the variable.

valueType

The data type of the variable.

defaultValue

The default value. Must be compatible with
valueType
and work with Unity serialization rules for SerializeField.

The kind of variable, defined by VariableKind.

Returns

Type

Description

IVariableThe newly created variable.

Remarks

Enclose this method with StateMachine.UndoBeginRecordStateMachine and StateMachine.UndoEndRecordStateMachine 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 state machine.
public IVariable CreateVariable<T>(string name, T defaultValue = default, VariableKind kind = VariableKind.Local)

Parameters

name

The name of the variable.

defaultValue

T
The default value. Must be compatible with
T
and work with Unity serialization rules for SerializeField.

The kind of variable, defined by VariableKind.

Returns

Type

Description

IVariableThe newly created variable.

Remarks

Enclose this method with StateMachine.UndoBeginRecordStateMachine and StateMachine.UndoEndRecordStateMachine to add this operation to the undo stack and to update the graph view with the changes.