Skip to content
Skillpedia
General coding6.6k Β· #13852

unreal-behavior-trees

What it does

This skill explains how to set up non-player character AI in Unreal Engine 5 using behavior trees. It is for developers building enemies or other game characters that make choices.

When to use it

  • βœ“When you are building an enemy or NPC that must choose its actions in Unreal Engine 5.
  • βœ“When you need to add conditions or periodic checks to an AI decision structure.
  • βœ“When you want to write custom behavior nodes or connect an AI controller to a behavior tree.

Skill link

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unreal/unreal-behavior-trees/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unreal/unreal-behavior-trees/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œMake my Unreal enemy patrol until it sees the player, then chase them.”

5 new skills a week. 1 minute to read.

How it works

It explains how to organize the tree with selectors and sequences, add conditions and background updates, and run the tree from an AI controller that uses a Blackboard for shared information.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Unreal Behavior Trees

Author NPC decision-making in UE5 with Behavior Trees driven by a Blackboard: structure the tree with composites, gate branches with decorators, keep state current with services, and run it from an AIController. Targets UE 5.8.

When to use

  • Use when building enemy/NPC AI: creating a BT_/BB_ asset pair, structuring Selector/Sequence branches, adding decorators (conditions) and services (periodic updates), writing custom BTTask/BTService nodes, or wiring an AIController to run the tree.
  • Use when the project has Behavior Tree (BT_) and Blackboard (BB_) assets and an AAIController.

When not to use: the concept of AI (FSM vs BT vs steering, cross-engine) β†’ game-ai. Pure navigation/pathing math is engine navmesh (BT's MoveTo uses it). Simple one-off logic may be cheaper as a small state machine than a full tree.

Behavior Tree or StateTree? UE 5.8 ships both, and Behavior Trees are not deprecated. StateTree is Epic's general-purpose hierarchical state machine: it combines BT-style selection with explicit States and Transitions. If the project already uses StateTree assets, or the AI is naturally a set of modes with clear transitions (patrol β†’ alert β†’ combat), check with the user before adding a Behavior Tree next to it. Keep using Behavior Trees where the project already has BT_/BB_ assets.

Core workflow

  1. Create the pair: a Blackboard (BB_) holds typed keys (the AI's memory: TargetActor, LastKnownLocation, bIsInvestigating); a Behavior Tree (BT_) references that Blackboard.
  2. Possess and run. An AAIController possesses the pawn and calls RunBehaviorTree(BT), which also initializes the referenced Blackboard.
  3. Structure with composites. Selector runs children left→right until one succeeds (priority/fallback: "attack, else chase, else patrol"). Sequence runs children until one fails (do-all: "move to cover → reload → peek"). Simple Parallel runs one main task alongside a secondary.
  4. Gate branches with Decorators that read Blackboard keys (e.g. "Has Target?" guards the combat branch). Set Observer Aborts so the tree re-evaluates when the key changes.
  5. Keep the Blackboard current with Services attached to a branch β€” they tick periodically (e.g. update TargetActor via a sight check) only while that branch is active.
  6. Do work in Tasks, which return Succeeded, Failed, or InProgress (latent tasks like MoveTo finish later).
  7. Verify with the Behavior Tree debugger during PIE β€” it highlights the running node and shows live Blackboard values, so you see exactly which branch executes.

Patterns

1. AIController that runs the tree (C++)

void AEnemyAIController::OnPossess(APawn* InPawn)
{
    Super::OnPossess(InPawn);
    if (BehaviorTree)                 // UPROPERTY(EditAnywhere) TObjectPtr<UBehaviorTree>
        RunBehaviorTree(BehaviorTree); // initializes & uses the Blackboard the BT references
}

2. A priority tree (node structure)

ROOT
└── Selector (try combat, else investigate, else patrol)
    β”œβ”€β”€ Sequence            [Decorator: Blackboard 'TargetActor' Is Set, Observer Aborts: Both]
    β”‚     β”œβ”€β”€ Task: MoveTo (TargetActor)          // latent: returns InProgress then Succeeded
    β”‚     └── Task: Attack
    β”œβ”€β”€ Sequence            [Decorator: 'LastKnownLocation' Is Set]
    β”‚     β”œβ”€β”€ Task: MoveTo (LastKnownLocation)
    β”‚     └── Task: Wait (3s) + clear key
    └── Task: Patrol (BTTask_FindPatrolPoint -> MoveTo)

Observer Aborts: Both makes the combat branch interrupt patrol the instant TargetActor is set, and bail out when it's cleared β€” this is what makes the AI feel reactive.

3. Updating the Blackboard from code (e.g. on seeing the player)

void AEnemyAIController::SetTarget(AActor* Target)
{
    if (UBlackboardComponent* BB = GetBlackboardComponent())
        BB->SetValueAsObject(TEXT("TargetActor"), Target);   // key name must match the BB asset
}
// Clear with BB->ClearValue(TEXT("TargetActor")); to drop back to a lower-priority branch.

Pitfalls

  • AI never starts β€” the pawn isn't possessed (set the Pawn's Auto Possess AI to "Placed in World or Spawned" and assign the AIController), or RunBehaviorTree was never called.
  • MoveTo instantly fails β€” no NavMesh in the level (add a Nav Mesh Bounds Volume), or the target is off the navmesh.
  • **Branch doesn't rea
FAQ

What is a Blackboard?

A Blackboard is a shared store of information, such as the player's position, that the behavior tree reads.

Should I use StateTree instead?

The skill says to check with the user first, since both systems exist in Unreal Engine 5.8 and a project may already use one.

Does this cover pathfinding math?

Not in depth. Movement uses the engine's navigation system, which is a separate topic.

Details

Original description by the author

Build NPC AI in Unreal Engine 5 with Behavior Trees and Blackboards: composites (Selector/Sequence), tasks, decorators, services, and running the tree from an AIController. Use when creating enemy/NPC AI, BT_/BB_ assets, custom BTTask or BTService nodes, or when the user mentions Behavior Tree, Blackboard, AIController, BTTask, decorator, or service.

repo: gamedev-skills/awesome-gamedev-agent-skills

Popularity

GitHub stars
6.6k
Ranking position
#13852
License
Apache-2.0
Updated
10/28/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills