https://github.com/Inspiaaa/UnityHFSM
A simple yet powerful hierarchical finite state machine for the Unity game engine. It is scalable and customisable by being class-based, but also supports functions (lambdas) for rapid prototyping.
Thanks to overloading, it minimises boilerplate code while still supporting generics.
It has a special focus on the temporal aspects of state transitions, making it ideal for timing and synchronisation sensitive problems.
Why use UnityHFSM?
- State machines are an amazingly easy way to write and organise game logic. (As soon as you have states, e.g. Walk, Run, Sneak, Jump, you can use a state machine)
- It's easy and straightforward to use
- It helps you tame complex behaviour (e.g. weapon handling -> cooling, ammo, reload, fire) or write AI for NPCs
- Helps you write self documenting code, that is maintainable and readable
- Reduces the boilerplate code required to write a state machine
- UnityHFSM is lightweight and efficient, making it perfect for solving small and big problems
- It is especially designed for Unity, and supports coroutines, which would otherwise be difficult to implement in a state machine
- No GC Allocations for state changes / updates / ... after setting up the state machine (-> No unwanted GC related lag spikes because of the state machine)
- The code is well documented
- It is not a component (MonoBehaviour) and therefore has a low overhead
- By being hierarchical, it can reduce the amount of duplicate code between states
In the wiki: