state-machine

Manage Unity game and AI states with hierarchical finite-state machines.

3|Updated Apr 8, 2026
One-click install
npx skills add https://github.com/XeldarAlz/KlondikeSolitaire --skill state-machine-xeldaralz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: state-machine
Source: https://github.com/XeldarAlz/KlondikeSolitaire/tree/main/.claude/skills/gameplay/state-machine
Command: npx skills add https://github.com/XeldarAlz/KlondikeSolitaire --skill state-machine-xeldaralz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This set of patterns provides a clean, reusable way to model game states (menu, gameplay, pause), AI behavior, and hierarchical FSMs using a single generic StateMachine<T> and an IState interface, reducing complexity and duplication.

Core Features & Use Cases

  • IState interface with Enter, Exit, Update, and FixedUpdate methods.
  • Generic StateMachine<T> that stores, transitions, and tracks current and previous states.
  • Support for high-level game state management (MainMenu, Gameplay, Pause, GameOver) and nested sub-states.
  • ScriptableObject-state patterns for designer-driven configuration.
  • Practical tips for debugging, testing, and safe transitions.

Quick Start

Instantiate a StateMachine with your owner type, register all states, and start with an initial state to drive behavior.

Frequently Asked Questions about state-machine

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

FAQPage Schema
How do I manage complex AI behavior and gameplay states in Unity without duplicating logic?

You can manage complex Unity AI and gameplay states by implementing a generic StateMachine<T> with an IState interface featuring Enter, Exit, Update, and FixedUpdate methods. This pattern cleanly separates state behaviors, reducing complexity and code duplication across player controllers, NPCs, and game managers.

How do I set up a state machine in Unity to handle menu, gameplay, and pause states?

To set up a Unity state machine for menu, gameplay, and pause states, instantiate a generic StateMachine with your owner type, register all states, and start with an initial state. This drives high-level game flow and supports nested sub-states for hierarchical FSMs.

Can I use ScriptableObjects to configure state machine transitions in Unity?

Yes, you can use ScriptableObject-state patterns for designer-driven configuration within your Unity state machine. This allows designers to configure state behaviors and transitions directly from the Unity Inspector without modifying the underlying codebase.

What is the best way to structure hierarchical FSMs for Unity game development?

The best way to structure hierarchical FSMs in Unity is using a reusable generic StateMachine<T> that tracks current and previous states. This framework supports nested sub-states, allowing you to nest state machines inside other states for complex AI behavior and high-level game management.

Does this Unity state machine pattern require specific dependencies or components?

No, this Unity state machine pattern requires no external dependencies or components. It relies entirely on a standard IState interface and a generic StateMachine<T> class, making it a self-contained framework that integrates natively into any Unity project.

How does the state machine handle safe transitions and debugging across Unity controllers?

The state machine handles safe transitions by tracking current and previous states while executing dedicated Enter and Exit methods. It includes practical tips for debugging and testing, ensuring safe transitions across player controllers, NPCs, and game managers.