StateMachine<TState> Class


A simple keyless Finite State Machine system.

This class doesn't keep track of any states other than the currently active one. See Animancer.FSM.StateMachine`2 for a system that allows states to be pre-registered and accessed using a separate key.
Base Types
  • Object
Derived Types
graph BT Type-->Base0["Object"] Type["StateMachine<TState>"] class Type type-node Derived0["StateMachine<TKey, TState>"]-->Type click Derived0 "/animancer/api/Animancer.FSM/StateMachine_2"


[HelpURL(StateExtensions.APIDocumentationURL + nameof(StateMachine<TState>) + "_1")]
public class StateMachine<TState> where TState : class, IState<TState>


Type Description

Type Parameters

Name Description


Name Summary
StateMachine() Constructs a new Animancer.FSM.StateMachine`1.
StateMachine(TState) Constructs a new Animancer.FSM.StateMachine`1 and immediately enters the `defaultState`.


Name Value Summary
CurrentState TState
The current state.


Name Value Summary
CanSetState(TState) bool
Checks if it is currently possible to enter the specified `state`. This requires Animancer.FSM.IState`1.CanExitState(`0) on the Animancer.FSM.StateMachine`1.CurrentState and Animancer.FSM.IState`1.CanEnterState(`0) on the specified `state` to both return true.
ForceSetState(TState) void
Calls Animancer.FSM.IState`1.OnExitState on the Animancer.FSM.StateMachine`1.CurrentState then changes to the specified `state` and calls Animancer.FSM.IState`1.OnEnterState on it.

This method does not check Animancer.FSM.IState`1.CanExitState(`0) or Animancer.FSM.IState`1.CanEnterState(`0). To do that, you should use Animancer.FSM.StateMachine`1.TrySetState(`0) instead.
ToString() string
Returns a string describing the type of this state machine and its Animancer.FSM.StateMachine`1.CurrentState.
TryResetState(TState) bool
Attempts to enter the specified `state` and returns true if successful.

This method does not check if the `state` is already the Animancer.FSM.StateMachine`1.CurrentState. To do so, use Animancer.FSM.StateMachine`1.TrySetState(`0) instead.
TrySetState(TState) bool
Attempts to enter the specified `state` and returns true if successful.

This method returns true immediately if the specified `state` is already the Animancer.FSM.StateMachine`1.CurrentState. To allow directly re-entering the same state, use Animancer.FSM.StateMachine`1.TryResetState(`0) instead.