This guide provides detailed instructions on using the State Manager System in an Unreal Engine 5 project, covering key workflows for managing actor states, triggering transitions, and extending the system with custom states and state machines. Users will learn how to enter and exit states, handle state transitions, and create custom state behaviors for Action RPGs or AI-driven systems. The guide is designed for developers and designers to effectively utilize state management for characters, enemies, or other actors.
Usage Guide
Entering and Exiting States
Trigger state changes for an actor using Gameplay Tags or state classes.
-
Ensure the
BP_StateManagerComponentis added to the actor (e.g.,BP_PlayerCharacterorBP_EnemyAI). -
Call
Enter State By TagorEnter State By Classto enter a state:Enhanced Input Action (IA_Attack, Triggered) -> Get Component By Class (Class: BP_StateManagerComponent) -> Enter State By Tag (StateTag: State.Attack) -
Bind to state events for additional logic:
BP_StateManagerComponent -> On State Begin (StateTag) -> Spawn Emitter At Location (Emitter: StateStartFX)BP_StateManagerComponent -> On State End (StateTag) -> Print String (Text: Exited State: StateTag) -
Exit a state by calling
EndStatein a customBP_BaseStateor transitioning to another state.
Managing State Transitions
Control transitions between states using BP_StateMachine or state logic.
-
In
BP_StateManagerComponent, run a state machine to handle transitions:Event Tick -> Get Component By Class (Class: BP_StateManagerComponent) -> Run State Machine By Tag (StateMachineTag: StateMachine.Combat) -
Send events to trigger transitions:
Event Enemy Detected -> Get Component By Class (Class: BP_StateManagerComponent) -> Send Event To State Machine (EventTag: Event.EnemyDetected) -
In a custom
BP_StateMachine, overrideRun State Machineto define transition logic:Run State Machine -> Is State Equal To Any (State.Patrol) -> Branch (True) -> Enter State By Tag (StateTag: State.Chase)
Processing Input Atoms
Use Input Atom assets to influence state transitions or behaviors.
-
In the Content Browser, locate a demo
Input Atom(e.g.,IA_AttackInput). -
Add the
Input Atomto the state manager:Event BeginPlay -> Get Component By Class (Class: BP_StateManagerComponent) -> Add Input Atom (InputAtom: IA_AttackInput) -
Check for the
Input Atomin a state or state machine:Run State Machine -> Has Input Atom (InputAtom: IA_AttackInput) -> Branch (True) -> Enter State By Tag (StateTag: State.Attack) -
Remove the
Input Atomwhen no longer needed:On State End -> Get Component By Class (Class: BP_StateManagerComponent) -> Remove Input Atom (InputAtom: IA_AttackInput)
Creating Custom States
Extend the system by creating new state classes for project-specific behaviors.
-
In the Content Browser, create a new Blueprint inheriting from
BP_BaseState(e.g.,BP_State_MyCustomState). -
In
BP_State_MyCustomState, set theState Tagproperty (e.g.,State.MyCustomState) in the Details panel. -
Override
CanEnterStateto define entry conditions:CanEnterState -> Is Character Dead? -> Branch (False) -> Return (True) -
Override
EnterStatefor entry logic:EnterState -> Play Animation Montage (Montage: AM_MyCustomAction) -
Override
EndStatefor cleanup:EndState -> Stop Animation Montage -
Add
BP_State_MyCustomStateto theState Classesarray inBP_StateManagerComponent’s Details panel.
Note:
When using the State Manager within Advanced ARPG Combat, the Player Info Data Asset and Enemy Info Data Assets are used to configure default states for Enemies and Players.
- Trigger the state in-game:
Enhanced Input Action (IA_MyAction, Triggered) -> Get Component By Class (Class: BP_StateManagerComponent) -> Enter State By Class (StateClass: BP_State_MyCustomState)
Creating Custom State Machines
Create a custom state machine to manage complex state transitions, such as AI behaviors.
-
Create a new Blueprint inheriting from
BP_StateMachine(e.g.,BP_MyStateMachine). -
Set a unique
State Tag(e.g.,StateMachine.MyStateMachine) in the Details panel. -
Override
Run State Machineto define transition logic:Run State Machine -> Is State Equal To Any (State.Idle) -> Branch (True) -> Get State Time -> Greater Than (Value: 5.0) -> Branch (True) -> Enter State By Tag (StateTag: State.Patrol) -
In
BP_StateManagerComponent, run the state machine:Event BeginPlay -> Get Component By Class (Class: BP_StateManagerComponent) -> Run State Machine By Class (StateMachineClass: BP_MyStateMachine) -
Send events to the state machine for dynamic transitions:
Event Player Detected -> Get Component By Class (Class: BP_StateManagerComponent) -> Send Event To State Machine (EventTag: Event.PlayerDetected) -
Add
BP_MyStateMachineto the State Classes array inBP_StateManagerComponentor activate it dynamically withRunStateMachineByClass.
Note:
When using the State Manager within Advanced ARPG Combat, the Player Info Data Asset and Enemy Info Data Assets are used to configure default states for Enemies and Players.
- Test the state machine in-game to ensure transitions occur as expected.
Example: AI Behavior State Machine
-
Create a child class of the default
BP_Behaviorclass included in the AdvancedARPGCombat > AdvancedCombatFramework > CoreCombatSystem > AI > States folder and call itBP_ExampleBehavior -
Modify Run State Machine to define AI transitions (e.g., from State.Idle to State.Pursue on enemy detection):
Run State Machine -> Has Input Atom (InputAtomTag: Input.EnemyDetected) -> Branch (Condition: True) -> Enter State By Tag (StateTag: State.Pursue) -
Add input atoms based on AI perception:
Event OnEnemyDetected -> Get BP_StateManagerComponent -> Add Input Atom (InputAtomTag: Input.EnemyDetected) -
Add
BP_ExampleBehaviorto the AI behavior State Manager (BP_BehaviorManagerComponent), located in theBP_BaseAIController.
NOTE:
This guide assumes the state manager is being used standalone. If Using State Machine with default Advanced ARPG Combat Project, the Behavior State Machine is set from the Enemy AI Info Data Asset. If using State Manager standalone, the behavior state machine will be added through the
BP_BehaviorManagerComponentin theBP_BaseAIController.
- Ensure the Behavior State Manager initialization function is called BEFORE the behavior tree runs
- Ensure the Behavior Tree is setup to work with the State Machine
NOTE:
Use the included
BP_BaseAIController,EnemyInfoDataAsset,BP_BaseEnemy, andBT_ExampleAI. Refer to the default included enemy AI in Advanced ARPG Combat if confused.
- Test the AI in-game to verify state transitions.
Troubleshooting
- State Not Entering:
- Confirm
StateTagorStateClassmatches the target state inEnter State By TagorEnter State By Class. - Check
CanEnterStatein the state class allows entry. - Ensure
BP_StateManagerComponentis not disabled on the actor.
- Confirm
- Transitions Not Happening:
- Verify
Run State Machine By TagorRun State Machine By Classreferences the correctBP_StateMachine. - Ensure
Send Event To State Machineuses a validEventTagdefined in the state machine. - Check transition logic in
Run State Machinefor errors.
- Verify
- Input Atoms Not Triggering:
- Confirm
Add Input Atomis called before checkingHas Input Atom. - Verify the correct
Input Atomasset is referenced.
- Confirm
- AI Behavior Not Working:
- Ensure
BP_BehaviorStateMachineis assigned and running inBP_EnemyAI. - Check that AI events (e.g.,
Event.EnemyDetected) are sent correctly.
- Ensure
Best Practices
- Workflows:
- Use hierarchical
Gameplay Tags(e.g.,State.Combat.Attack,Event.AI.PlayerDetected) for organization. - Test custom states with existing demo state machines before creating new ones.
- Bind
On State BeginandOn State Endto debug state changes during development.
- Use hierarchical
- Pitfalls to Avoid:
- Don’t skip setting
State Tagin custom states or state machines to avoid undefined behavior. - Avoid complex logic in
EnterStateorEndState; delegate toRun State Machinefor transitions. - Don’t call
Run State Machineevery frame unless necessary; use events for efficiency.
- Don’t skip setting