Finite State Machine
Clean, extensible state machine for AI, player states, and game flow. Uses ScriptableObject states.
4 scripts advanced Core system Advanced AI and game flow control
The full files for this kit are not published yet, so there is no download. The preview shows how the main pieces fit.
What is inside
- StateMachine.cs Not published yet
- State.cs Not published yet
- StateTransition.cs Not published yet
- AIStateMachine.cs Not published yet
What it does
- ScriptableObject-based state definitions
- Clean enter/execute/exit lifecycle
- Conditional transitions with priorities
- Debug visualization in editor
- AI state machine variant included
- Works with any MonoBehaviour
Setup, in order
- Import all scripts
- Create State ScriptableObjects for each state
- Define transitions between states
- Attach StateMachine to your character
- Assign initial state and transition rules
If something does not work
- The character never leaves its first state
- Transitions are only checked when their conditions can become true. Check each transition's condition and priority, and that the state machine has an initial state assigned.
- Two characters share state by accident
- State ScriptableObjects are shared assets. Keep per-character data such as timers and targets on the character, not on the state asset.
Preview
An excerpt of the kit's main types, and the Inspector fields they expose.
Inspector
Fields from the kit's preview excerpt; the full kit has more.
Initial State None (State)
Excerpt
C#
// State.cs - Base state class
public abstract class State : ScriptableObject
{
public abstract void OnEnter(StateMachine machine);
public abstract void OnExecute(StateMachine machine);
public abstract void OnExit(StateMachine machine);
}
// StateMachine.cs - Core state machine
public class StateMachine : MonoBehaviour
{
[SerializeField] private State initialState;
public State CurrentState { get; private set; }
public void TransitionTo(State newState) { /* ... */ }
}