state-machine

Generate Unity C# finite state machines with reusable StateMachine<T> classes.

Updated May 6, 2026
One-click install
npx skills add https://github.com/BasarEkinci/memory-card-game --skill state-machine-basarekinci
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: state-machine
Source: https://github.com/BasarEkinci/memory-card-game/tree/main/.claude/skills/gameplay/state-machine
Command: npx skills add https://github.com/BasarEkinci/memory-card-game --skill state-machine-basarekinci

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves messy, hard-to-debug gameplay and AI logic caused by scattered conditional branches by providing a reusable finite state machine pattern.

Core Features & Use Cases

  • Type-safe IState contracts: Define states with Enter/Exit plus Update and FixedUpdate for frame- and physics-timed behavior.
  • Reusable generic StateMachine<T>: Register states once, transition by type, and reuse state instances to avoid per-transition allocations.
  • Real-world state patterns: Use it for player states (idle/run/jump), high-level game flow (menu/loading/gameplay/pause), enemy AI (patrol/chase/attack), hierarchical FSMs, event-driven transitions, and ScriptableObject-driven configurable states.
  • Testing-friendly design: States are plain C# classes that are easier to unit test without Unity dependencies.

Quick Start

Ask the AI to generate a Unity C# state machine setup for your game with an IState interface, a generic StateMachine<T>, and example transitions for player movement plus a pause/resume game flow.

Frequently Asked Questions about state-machine

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure enemy AI behavior in Unity without messy conditional branches?

Using a finite state machine pattern structures enemy AI into distinct states with Enter, Exit, and Update methods managed by a reusable generic StateMachine, eliminating scattered conditional branches and making your Unity AI logic easier to debug and maintain.

What is the best way to manage overall game flow like menu, loading, and pause in Unity?

A finite state machine handles overall game flow by defining menu, loading, gameplay, pause, and gameover phases as individual states, enabling safe event-driven transitions and clean separation between high-level game phases.

Can I use ScriptableObjects to configure state machine parameters for Unity gameplay?

Yes, the finite state machine supports designer-configurable ScriptableObject parameters, allowing designers to tweak state behaviors and transitions without modifying code, streamlining the gameplay architecture workflow.

How do I unit test Unity player controller states without Unity dependencies?

You can unit test player controller states by implementing them as plain C# classes with IState contracts, which removes Unity dependencies and allows direct testing of finite state machine transitions and behaviors.

When should I use a hierarchical finite state machine for gameplay architecture?

Use a hierarchical finite state machine when a standard FSM causes state explosion, delegating sub-states to avoid complexity while maintaining clean Enter, Exit, and Update logic for complex enemy AI phases.

Does a generic finite state machine avoid memory allocations during state transitions?

Yes, a reusable generic StateMachine registers states once and reuses state instances, applying minimal allocation practices to prevent garbage collection spikes during frequent gameplay and AI state transitions.