StateMachines

com.cupkekgames.statemachines — ScriptableObject-driven state machine framework. States are authored as StateSO assets; transitions are authored on a TransitionTableSO; an editor window provides graph-style authoring + runtime debugging.

Authoring model

A state machine is two assets:

  • StateSO — a state. Holds a [SerializeReference] List<IStateAction> so each state's behavior is composed from polymorphic action instances authored in the Inspector.
  • TransitionTableSO — the transition graph. Maps (fromState, toState, conditions) triples; condition data is also [SerializeReference].

At runtime, the StateMachine MonoBehaviour clones each authored action via IStateAction.Clone() so per-instance state stays isolated, then drives OnStateEnter / OnUpdate / OnStateExit.

Polymorphic data via [SerializeReference]

Earlier versions used per-action factory ScriptableObjects (StateActionSO, StateConditionSO, StateMachineActionTryTransitionSO, …). Those are gone. Action and condition data is now stored inline on StateSO / TransitionTableSO via [SerializeReference], drawn with a type-picker dropdown.

To author a new action:

csharp
[Serializable] public class PlayAnimationAction : StateAction { [SerializeField] private string _kind = AnimationKinds.Idle; private IAnimationStateController _animations; public override void Awake(StateMachine sm) => _animations = sm.GetComponent<IAnimationStateController>(); public override void OnStateEnter() => _animations?.Play(_kind); }

The action shows up immediately in the StateSO Inspector's + dropdown — no SO asset to create.

What's inside

Runtime (CupkekGames.StateMachines.asmdef)

  • StateMachine (MonoBehaviour) — drives state transitions
  • State / StateAction / StateCondition / StateTransition — runtime building blocks (Clone'd from the authored templates)
  • IStateAction / IStateCondition — pluggable contracts
  • StateSO / TransitionTableSO — authoring assets
  • StateMachineActionTryTransition — built-in action that triggers transition evaluation on state entry
  • StateMachineUpdateMode — when the FSM ticks

Editor (CupkekGames.StateMachines.Editor.asmdef)

  • StateMachineEditor / StateEditor — Inspector tooling
  • TransitionTableEditor + TransitionTableEditorWindow — graph-style transition authoring
  • ScriptTemplates — quick-create templates for new actions / conditions

Asmdef + namespace

CupkekGames.StateMachines (runtime), CupkekGames.StateMachines.Editor (editor). Pluralized from the original CupkekGames.StateMachine to avoid the namespace = class collision.

Dependencies

None.

Repository

Cupkek-Games/CupkekGames-StateMachines

Settings

Theme

Light

Contrast

Material

Dark

Dim

Material Dark

System

Sidebar(Light & Contrast only)

Light
Dark

Font Family

DM Sans

Wix

Inclusive Sans

AR One Sans

Direction

LTR
RTL