The State Manager System is a Blueprint-based system for Unreal Engine 5 projects, designed to manage and control multiple states for actors, such as characters or AI, in complex Action RPGs. It enables developers to define state behaviors, handle transitions, and respond to events, simplifying the implementation of finite state machines (FSMs). The system addresses the need for modular, reusable state management, making it easy to create and transition between states like idle, attacking, or stunned. Targeted at game developers and designers building RPGs or AI-driven games, its standout features include flexible state transitions, Gameplay Tag-based state identification, and robust support for AI behavior through state machines.
System Architecture
The State Manager System revolves around the BP_StateManagerComponent, which manages states and transitions for an actor. Blueprints handle state logic, transitions, and input processing, with no C++ dependencies for accessibility. The system uses Gameplay Tags for state and event identification, and Input Atom assets for input processing, enabling modular state-driven behavior.
-
Key Blueprint Classes:
- BP_StateManagerComponent: Core component that manages an actor’s states, tracks the active state, and facilitates transitions. It handles state entry, exit, and event dispatching.
- BP_BaseState: UObject-derived Blueprint defining state behavior, including entry (
EnterState), exit (EndState), and transition logic (Run State Machine). - BP_StateMachine: UObject-derived Blueprint extending
BP_BaseState, acting as a centralized FSM to manage state transitions in response to events or inputs. Input Atom: Data Asset representing an indivisible unit of input data, used to trigger state transitions or events in the FSM.
-
Data Flow:
BP_StateManagerComponentis added to an actor (e.g.,BP_PlayerCharacter) and configured with default states viaState ClassesorDefault State.- States are entered using
Enter State By TagorEnter State By Class, triggeringOn State Beginand executingEnterStatelogic in the correspondingBP_BaseState. BP_StateMachineprocesses events viaSend Event To State Machineor runs transitions viaRun State Machine By Tag, callingRun State Machinein the state class.Input Atomassets are added to the state manager viaAdd Input Atom, influencing transitions or state behavior.- State exits trigger
On State EndandEndState, allowing cleanup or notifications.
graph TD A[Actor] -->|Owns| B[BP_StateManagerComponent] B -->|Manages| C[BP_BaseState] B -->|Manages| D[BP_StateMachine] B -->|Processes| E[Input Atom] C -->|Defines| F[EnterState/EndState] D -->|Controls| G[Run State Machine] B -->|Dispatches| H[On State Begin/End] E -->|Triggers| G
Core Features
- State Management:
- Manages multiple states for an actor, allowing entry and exit via
Enter State By TagorEnter State By Class. - Benefits: Simplifies state-driven behavior for characters or AI, reducing complexity in state handling.
- Manages multiple states for an actor, allowing entry and exit via
- Flexible State Transitions:
- Supports transitions between states using
Run State MachineinBP_BaseStateorBP_StateMachine, driven by events or conditions. - Benefits: Enables dynamic state changes, such as switching from idle to attacking based on input or AI logic.
- Supports transitions between states using
- Event Dispatching:
- Dispatches
On State BeginandOn State Endevents to notify other systems of state changes. - Benefits: Facilitates integration with gameplay systems, like triggering animations or effects on state entry/exit.
- Dispatches
- Input Atom Processing:
- Processes
Input Atomassets to trigger state transitions or events viaAdd Input AtomandSend Event To State Machine. - Benefits: Provides a modular way to handle input-driven state changes, enhancing flexibility.
- Processes
- State Time Tracking:
- Tracks active state duration via
bTrackStateActiveTimeandGet State Time, useful for timed states like stuns or buffs. - Benefits: Enables precise control over state behavior based on duration.
- Tracks active state duration via
- AI Behavior Support:
- Uses
BP_StateMachineto define complex AI behaviors, managing transitions for states like patrolling, chasing, or attacking. - Benefits: Streamlines the creation of advanced, modular AI FSMs for bosses or enemies.
- Uses