This guide provides detailed instructions on using the Combat AI Behavior System within the Advanced ARPG Combat framework in Unreal Engine 5. It covers key workflows for managing enemy AI behaviors, triggering combat actions, configuring patrol routes, and extending the system with custom AI behaviors, abilities, and configurations. The guide is designed for developers and designers to effectively utilize the system for creating dynamic enemy AI in Action RPGs.
Managing AI Behaviors
Control enemy AI behavior using the BP_BehaviorManagerComponent and SM_Humanoid_CombatBehavior.
-
Select a
BP_BaseEnemyin the level or spawned viaBP_EnemySpawner. -
In the Details panel, locate
BP_BehaviorManagerComponentand ensure it references aSM_Humanoid_CombatBehavior(set viaBP_EnemyInfo). -
Adjust behavior properties in the referenced
BP_EnemyInfo(e.g.,BP_EnemyInfo_Humanoid):- Set
Attack Distancefor combat range. - Modify
Enemy Aggressionto control attack frequency.
BP_EnemyInfo -> Behavior -> Set Attack Distance (Value: 500.0) - Set
-
Send events to trigger behavior changes:
BP_BaseAIController -> UpdateTarget -> Set Blackboard Value As Object (Key: TargetActor, Value: Player) -> Send Event To State Machine (EventTag: Event.PlayerDetected)
Triggering Combat Actions
Execute AI combat abilities using Behavior Tree tasks and GA_EnemyAbility classes.
-
Open the Behavior Tree (e.g.,
BT_ExampleAI) set inBP_EnemyInfo. -
Add a task node to execute an ability (e.g.,
GA_EnemyMeleeAttack):Behavior Tree -> Task: TryActivateAbilitiesByTag -> Set Blackboard Key (Key: AbilityTag, Value: Ability.MeleeAttack) -
Configure attack ranges in the Behavior Tree (e.g., close, medium, far) to select appropriate abilities.
-
Ensure
Default Ability SetsinBP_EnemyInfoincludes the ability:BP_EnemyInfo -> Abilities -> Default Ability Sets -> Add (Class: GA_EnemyMeleeAttack)
Configuring Patrol Routes
Set up AI patrolling using BP_PatrolComponent and BP_PatrolPath.
-
Place a
BP_PatrolPathactor in the level. -
In the Details panel, adjust
Patrol Pointsusing the 3D widget to define the route. -
Select a
BP_BaseEnemyand, in itsBP_PatrolComponent, setPatrol Pathto theBP_PatrolPathin the level. -
Optionally, if using
BP_EnemySpawnerset thePatrol Pathto theBP_PatrolPathin the level. -
Configure patrol settings:
BP_PatrolComponent -> Set bLoopPatrolPath (Value: True) -
If using with a behavior state manager, ensure to set the default behavior state to
Behavior.Patrolin theEnemyInfoDataAssetto ensure the AI starts with Patrol behavior. -
Ensure the Behavior Tree includes a patrol task:
Behavior Tree -> Task: Move To Patrol Point -> Set Blackboard Key (Key: PatrolPoint, Value: Next Patrol Point)
Managing Health and Ragdoll
Handle AI health bars and ragdoll effects during combat.
-
On damage, trigger the health bar:
BP_BaseEnemy -> OnDamageApplied -> ShowHealthBar -
On death, enable ragdoll:
BP_BaseEnemy -> OnDamageApplied -> Is Health Zero? -> Branch (True) -> EnableRagdoll -
Configure
PelvisBoneNameinBP_BaseEnemyto match the AI’s skeletal mesh:BP_BaseEnemy -> Set PelvisBoneName (Value: pelvis)
Creating Custom AI Behaviors
Extend the system by creating a custom behavior state machine.
-
Create new behavior tag in gameplay tag manager (e.g.,
Behavior.MyCustomBehavior) -
Open
SM_Humanoid_CombatBehaviorand modify theRunStateMachineevent to add the new behavior to the switch statement and edit existing behaviors to configure when to transition into the new state. -
Optionally, Create a new Blueprint inheriting from
SM_CombatBehavior(e.g.,SM_MyCombatBehavior). -
Override
RunStateMachineandUpdateBehaviorto define custom behavior and transitions:UpdateBehavior -> Is State Equal To Any (State.Idle) -> Branch (True) -> Has Blackboard Value (Key: TargetActor) -> Branch (True) -> Enter State By Tag (StateTag: State.Chase) -
Adjust behavior properties (e.g.,
Attack Distance,Enemy Aggression) in the Details panel. -
In
BP_EnemyInfo, setBehavior Classesto includeSM_MyCombatBehavior. -
Update the Behavior Tree to support new states:
Behavior Tree -> Task: Custom Action -> Set Blackboard Key (Key: BehaviorTag, Value: Behavior.MyCustomAction)
Creating Custom Enemy Abilities
Develop new AI abilities for unique combat behaviors.
- Create a new Blueprint inheriting from the appropriate enemy ability class.
- For completely custom enemy abilities inherit from
GA_EnemyAbility(e.g.,GA_MyEnemyAbility) - For Attack Abilities inherit from
GA_EnemyMeleeAttack(e.g.,GA_MyEnemyAttack) - For Dodge a Dodge Ability inherit from
GA_EnemyDodge(e.g.,GA_MyEnemyDodge)
- For completely custom enemy abilities inherit from
NOTE:
There are several default enemy abilities for you to inherit from and configure without the need to write any code. Check
AdvancedARPGCombat > MeleeCombatSystem > Blueprints > Abilities > AIto see what default abilities you can inherit your custom ability from.
-
Set ability properties (e.g.,
Attack Montage,Gameplay Tags) in the Details panel. -
If using a default included enemy action ability such as Attack or Dodge, simply set the desired animation montage.
-
Configure optional Ability Montage properties
- Set
AbilityEndTypeto eitherAutomaticorManualdepending on use case. If manual the ability will need to be ended by adding theAN_EndAbilityanim notify to the ability montage. - Configure
EndTimeMultipliervalue for automatic ability ending (e.g.,0.8) - Set Montage
PlayRateto desired value (e.g.,1.0) - Set
InTimeToStartMontageAtto desired value to change when the montage starts - Configure
StartSectionNameto desired value to change the default start montage section
- Set
-
For completely custom enemy abilities, Override
ActivateAbilityto define behavior:ActivateAbility -> Play Montage (Montage: AM_MyAttack) -> Apply Gameplay Effect (Effect: GE_Damage) -
Add the ability to
Default Ability SetsinBP_EnemyInfo:BP_EnemyInfo -> Abilities -> Default Ability Sets -> Add (Class: GA_MyEnemyAbility) -
Update the Behavior Tree to trigger the ability:
Behavior Tree -> Task: Perform Ability -> Set Blackboard Key (Key: AbilityTag, Value: Ability.MyCustomAttack)
Creating Custom Enemy AI
Create a new enemy type with custom configurations.
- Create a new Blueprint inheriting from
BP_BaseEnemy(e.g.,BP_MyEnemy). - Set
AI Controller ClasstoBP_BaseAIControllerin the Details panel. - Create a new
BP_EnemyInfo(e.g.,BP_MyEnemyInfo):- Set
AI Pawn ClasstoBP_MyEnemy. - Assign a custom
Anim ClassandCombat Style. - Add custom abilities and behaviors (e.g.,
SM_MyCombatBehavior,GA_MyEnemyAbility). - Add custom behavior tree or select included behavior tree
- Configure hostile tags to ensure the enemy can detect hostiles
- Set
- Configure
BP_MyEnemyto useBP_MyEnemyInfo:BP_MyEnemy -> Event BeginPlay -> SetEnemyInfoRef (EnemyInfo: BP_MyEnemyInfo) - Place
BP_MyEnemyin the level or useBP_EnemySpawnerwithBP_MyEnemyInfo.
Notes
- Use
BP_EnemyInfofor all AI configurations to leverage async loading and simplify setup. - Combine Behavior Tree tasks and
SM_Humanoid_CombatBehaviorproperties for fine-tuned AI behavior. - Test custom behaviors with demo assets to understand default interactions before scaling complexity.
- Ensure
Gameplay Tagsare unique to avoid conflicts between AI and player systems.
Troubleshooting
- AI Not Transitioning States:
- Verify
SM_Humanoid_CombatBehavioris set inBP_EnemyInfoand referenced byBP_BehaviorManagerComponent. - Ensure
UpdateBehaviorinSM_Behaviorprocesses validGameplay Tagsor Blackboard values. - Check Behavior Tree tasks are setting correct Blackboard keys.
- Verify
- Abilities Not Executing:
- Confirm
Default Ability SetsinBP_EnemyInfoincludes the ability class. - Verify
Combat StyleinBP_EnemyInfomatches the ability’s requirements. - Ensure
ActivateAbilityin the ability class is correctly configured.
- Confirm
- Patrol Not Working:
- Check
BP_PatrolPathis assigned toBP_PatrolComponentandPatrol Pointsare defined. - Ensure a
Nav Mesh Bounds Volumecovers the patrol area.
- Check
- Health Bar or Ragdoll Issues:
- Verify
OnDamageAppliedcallsShowHealthBarandEnableRagdollinBP_BaseEnemy. - Confirm
PelvisBoneNamematches the AI’s skeletal mesh.
- Verify
Best Practices
- Workflows:
- Start with demo
BP_EnemyInfoandSM_Humanoid_CombatBehaviorto test default behaviors before customizing. - Use hierarchical
Gameplay Tags(e.g.,Behavior.Combat.Attack,Enemy.Hostile.Player) for clarity. - Regularly test AI in-game to validate Behavior Tree and FSM interactions.
- Start with demo
- Pitfalls to Avoid:
- Don’t skip setting
HostileTagsinBP_EnemyInfoorBP_BehaviorManagerComponentto ensure proper targeting. - Don’t forget to add Behavior Tree to
BP_EnemyInfo - Don’t hard-reference assets; use
BP_EnemyInfofor async loading.
- Don’t skip setting