StateTree Integration
Documentation Unreal Engine AI StateTree
Guide to StateTree tasks, structure, and integration with the combat system.
Available StateTree Tasks
| Task | Purpose | When to Use |
|---|---|---|
STTask_BuildDecisionContext | Gathers combat data | Every tick in root state |
STTask_AIMovement | Evaluates and applies movement | Every tick in root state |
STTask_PollAction | Scores and selects action | On entering decision state |
STTask_DoAction | Triggers execution of chosen action | On entering execute state |
STTask_UpdateActionSet | Swaps ActionSet | When changing AI behavior |
STTask_PollCombatRole | Polls current combat role | Every tick, outputs role tag |
STTask_PollFocusActor | Polls controller focus actor | Every tick, outputs target reference |
STTask_SyncActionSet | Syncs ActionSet from pawn's SECActionSetComponent | On entering role state |
STTask_SyncMovementProfile | Syncs MovementProfile for current role | On entering role state |
All StateTree tasks work with anyAAIControllerthat has aSECCombatControllerComponent. They use the component's static resolution helpers to find AIConfig and combat role data.
Typical StateTree Structure
Root (Always Active)
├─ BuildDecisionContext [Tick]
├─ AIMovement [Tick]
│
├─ Idle State
│ └─ Transition → Combat (when target acquired)
│
└─ Combat State
├─ Decision State
│ ├─ PollAction [Enter]
│ └─ Transition → Execute (when action chosen)
│
└─ Execute State
├─ DoAction [Enter]
└─ Transition → Decision (when complete)
Task Details
STTask_BuildDecisionContext
Inputs:
- AIController (Object)
- DefaultAggressionLevel
- WindowIdIntervalSeconds
Attribute Inputs (Optional):
- HealthAttribute (FGameplayAttribute)
- MaxHealthAttribute (FGameplayAttribute)
- StaminaAttribute (FGameplayAttribute)
- MaxStaminaAttribute (FGameplayAttribute)
Point these at your GAS AttributeSet properties (e.g.
UMyAttributeSet::GetHealthAttribute()). When set, the task reads live values from the pawn's ASC every tick. When left empty, it falls back to BasicHealthComponent (if present) or safe defaults (health percentage 1.0, max health 100).Outputs:
- OutDecisionContext (FDecisionContext struct)
What it does:
- Calculates distance and angle to target
- Reads health and stamina from GAS attributes (or BasicHealthComponent fallback)
- Evaluates health percentages
- Gathers gameplay tags from target
STTask_PollAction
Inputs:
- AIController
- Context (FDecisionContext)
- EvaluationCooldown
- DebugLog
Outputs:
- ChosenAction (FChosenAction)
What it does:
- Scores all actions in ActionSet
- Applies evaluators
- Checks cooldowns
- Selects best valid action
STTask_DoAction
Inputs:
- Actor
- AIController
- InChosenAction (FChosenAction)
- DebugLog
What it does:
- If Ability: Activates via ASC
- If BT: Runs behavior tree sequence
- Waits for SEC.Action.End event
- Completes when action finishes