Unity-StateMachines

This packages offers astract classes for FSM (Finite State Machine) and HFSM (Hierarchical Finite State Machine) patterns.


Project maintained by kevincastejon Hosted on GitHub Pages — Theme by mattgraham

StateMachines

This packages offers astract classes for FSM (Finite State Machine) and HFSM (Hierarchical Finite State Machine) patterns.

Do not waste time with all the state machine mechanics anymore, just implement the logic!

You can even save more time by using the scripts generator (Window > FSM/HFSM Generator)

See online documentation

Get the Unity package

See my other Unity packages

Complete API Documentation

Usages

FSM

Here is a simple example of a state machine with three states A, B and C.

HFSM

Here is a simple example of a state machine with three states A, B and C, with the B state being also a nested state machine with its own states (SUB_A, SUB_B and SUB_C)

You can optionally reference this component into the StateMachine hierarchy by passing it to the CreateRootStateMachine method optional second parameter, and you can access this reference from any of the stateMachines/states in the hierarchy via the RootComponent property (which is MonoBehaviour type, so you may have to cast it). That can be helpfull for accessing scene objects and components from inside the stateMachines and states scripts.

Here is an example of wrapper component for the above example, plus an Animator component reference passed to the HFSM and used inside the states classes.

Generators

You can use generators windows for both FSM and HFSM to generate skeleton, ready-to-implement scripts, along with some options.

Open these windows via the menu Window > FSM/HFSM Generator

Screen1 Screen2 Screen3