StateTree Integration

Documentation Unreal Engine AI StateTree

Guide to StateTree tasks, structure, and integration with the combat system.


Available StateTree Tasks

TaskPurposeWhen to Use
STTask_BuildDecisionContextGathers combat dataEvery tick in root state
STTask_AIMovementEvaluates and applies movementEvery tick in root state
STTask_PollActionScores and selects actionOn entering decision state
STTask_DoActionTriggers execution of chosen actionOn entering execute state
STTask_UpdateActionSetSwaps ActionSetWhen changing AI behavior
STTask_PollCombatRolePolls current combat roleEvery tick, outputs role tag
STTask_PollFocusActorPolls controller focus actorEvery tick, outputs target reference
STTask_SyncActionSetSyncs ActionSet from pawn's SECActionSetComponentOn entering role state
STTask_SyncMovementProfileSyncs MovementProfile for current roleOn entering role state
All StateTree tasks work with any AAIController that has a SECCombatControllerComponent. 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