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_BaseEnemy
in the level or spawned viaBP_EnemySpawner
. -
In the Details panel, locate
BP_BehaviorManagerComponent
and ensure it references aSM_Humanoid_CombatBehavior
(set viaBP_EnemyInfo
). -
Adjust behavior properties in the referenced
BP_EnemyInfo
(e.g.,BP_EnemyInfo_Humanoid
):- Set
Attack Distance
for combat range. - Modify
Enemy Aggression
to 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 Sets
inBP_EnemyInfo
includes 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_PatrolPath
actor in the level. -
In the Details panel, adjust
Patrol Points
using the 3D widget to define the route. -
Select a
BP_BaseEnemy
and, in itsBP_PatrolComponent
, setPatrol Path
to theBP_PatrolPath
in the level. -
Optionally, if using
BP_EnemySpawner
set thePatrol Path
to theBP_PatrolPath
in 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.Patrol
in theEnemyInfoDataAsset
to 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
PelvisBoneName
inBP_BaseEnemy
to 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_CombatBehavior
and modify theRunStateMachine
event 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
RunStateMachine
andUpdateBehavior
to 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 Classes
to 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 > AI
to 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
AbilityEndType
to eitherAutomatic
orManual
depending on use case. If manual the ability will need to be ended by adding theAN_EndAbility
anim notify to the ability montage. - Configure
EndTimeMultiplier
value for automatic ability ending (e.g.,0.8
) - Set Montage
PlayRate
to desired value (e.g.,1.0
) - Set
InTimeToStartMontageAt
to desired value to change when the montage starts - Configure
StartSectionName
to desired value to change the default start montage section
- Set
-
For completely custom enemy abilities, Override
ActivateAbility
to define behavior:ActivateAbility -> Play Montage (Montage: AM_MyAttack) -> Apply Gameplay Effect (Effect: GE_Damage)
-
Add the ability to
Default Ability Sets
inBP_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 Class
toBP_BaseAIController
in the Details panel. - Create a new
BP_EnemyInfo
(e.g.,BP_MyEnemyInfo
):- Set
AI Pawn Class
toBP_MyEnemy
. - Assign a custom
Anim Class
andCombat 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_MyEnemy
to useBP_MyEnemyInfo
:BP_MyEnemy -> Event BeginPlay -> SetEnemyInfoRef (EnemyInfo: BP_MyEnemyInfo)
- Place
BP_MyEnemy
in the level or useBP_EnemySpawner
withBP_MyEnemyInfo
.
Notes
- Use
BP_EnemyInfo
for all AI configurations to leverage async loading and simplify setup. - Combine Behavior Tree tasks and
SM_Humanoid_CombatBehavior
properties for fine-tuned AI behavior. - Test custom behaviors with demo assets to understand default interactions before scaling complexity.
- Ensure
Gameplay Tags
are unique to avoid conflicts between AI and player systems.
Troubleshooting
- AI Not Transitioning States:
- Verify
SM_Humanoid_CombatBehavior
is set inBP_EnemyInfo
and referenced byBP_BehaviorManagerComponent
. - Ensure
UpdateBehavior
inSM_Behavior
processes validGameplay Tags
or Blackboard values. - Check Behavior Tree tasks are setting correct Blackboard keys.
- Verify
- Abilities Not Executing:
- Confirm
Default Ability Sets
inBP_EnemyInfo
includes the ability class. - Verify
Combat Style
inBP_EnemyInfo
matches the ability’s requirements. - Ensure
ActivateAbility
in the ability class is correctly configured.
- Confirm
- Patrol Not Working:
- Check
BP_PatrolPath
is assigned toBP_PatrolComponent
andPatrol Points
are defined. - Ensure a
Nav Mesh Bounds Volume
covers the patrol area.
- Check
- Health Bar or Ragdoll Issues:
- Verify
OnDamageApplied
callsShowHealthBar
andEnableRagdoll
inBP_BaseEnemy
. - Confirm
PelvisBoneName
matches the AI’s skeletal mesh.
- Verify
Best Practices
- Workflows:
- Start with demo
BP_EnemyInfo
andSM_Humanoid_CombatBehavior
to 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
HostileTags
inBP_EnemyInfo
orBP_BehaviorManagerComponent
to ensure proper targeting. - Don’t forget to add Behavior Tree to
BP_EnemyInfo
- Don’t hard-reference assets; use
BP_EnemyInfo
for async loading.
- Don’t skip setting