Represents the core definition of a state machine and defines its behavior.
StateMachine serves as the central entry point for:
To register a state machine type and associate it with a custom file extension and configuration options,
apply the StateMachineAttribute to your custom StateMachine class.
You can further control the state machine's behavior using the
StateMachineOptions enum, which defines traits.
Use the StateMachineDatabase utility class to create, load, and save state machine assets in the Unity Editor.
State machines are serialized assets. You can create them through the editor UI with
StateMachineDatabase.PromptInProjectBrowserToCreateNewAsset or load them from disk with
StateMachineDatabase.LoadStateMachine.
| Property | Description |
|---|---|
| AssetGuid | The GUID of the asset file associated with this state machine. |
| AvailableVariableTypes | The set of types offered in the blackboard for variable creation. |
| ID | The globally unique identifier for this state machine. |
| Name | The name of the state machine. |
| StateCount | The number of IStates in the state machine. |
| VariableCount | The number of IVariables declared in the state machine. |
| Method | Description |
|---|---|
| AddState | Adds a state to the state machine. |
| CreateVariable | Creates and adds a new variable to the state machine. |
| GetState | Retrieves a state in the state machine by its index. |
| GetStates | Retrieves all states in the state machine. |
| GetTransitions | Retrieves the transitions that connect one state to another. |
| GetVariable | Retrieves a variable declared in the state machine by index. |
| GetVariables | Retrieves all variables declared in the state machine. |
| OnDisable | Called when the state machine is unloaded, or goes out of scope in the editor. |
| OnEnable | Called when the state machine is created or loaded in the editor. |
| OnStateMachineChanged | Called after the state machine has changed. |
| RemoveState | Removes a state from the state machine. |
| RemoveVariable | Removes a variable from the state machine. |
| UndoBeginRecordStateMachine | Signals the beginning of an undoable operation. |
| UndoEndRecordStateMachine | Signals the end of an undoable operation. Sends the undo data to the editor undo system and refreshes the graph view with the changes made. |
| Method | Description |
|---|---|
| BuildAvailableVariableTypes | Builds the set of variable types offered in the blackboard for variable creation. |