Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


StateMachine

Represents the core definition of a state machine and defines its behavior.
Read time 2 minutesLast updated 7 days ago

Definition

public class StateMachine

Remarks

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.

Properties

Property

Description

AssetGuidThe
GUID
of the asset file associated with this state machine.
AvailableVariableTypesThe set of types offered in the blackboard for variable creation.
IDThe globally unique identifier for this state machine.
NameThe name of the state machine.
StateCountThe number of IStates in the state machine.
VariableCountThe number of IVariables declared in the state machine.

Methods

Method

Description

AddStateAdds a state to the state machine.
BuildAvailableVariableTypesBuilds the set of variable types offered in the blackboard for variable creation.
ConnectCreates a transition from one state to another.
CreateVariableCreates and adds a new variable to the state machine.
DisconnectRemoves all transitions that go from one state to another.
GetStateRetrieves a state in the state machine by its index.
GetStatesRetrieves all states in the state machine.
GetTransitionsRetrieves the transitions that connect one state to another.
GetVariableRetrieves a variable declared in the state machine by index.
GetVariablesRetrieves all variables declared in the state machine.
OnDisableCalled when the state machine is unloaded, or goes out of scope in the editor.
OnEnableCalled when the state machine is created or loaded in the editor.
OnStateMachineChangedCalled after the state machine has changed.
RemoveStateRemoves a state from the state machine.
RemoveVariableRemoves a variable from the state machine.
UndoBeginRecordStateMachineSignals the beginning of an undoable operation.
UndoEndRecordStateMachineSignals the end of an undoable operation. Sends the undo data to the editor undo system and refreshes the graph view with the changes made.