Loading...
Loading...
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.
npx skill4agent add gamedev-skills/awesome-gamedev-agent-skills unreal-behavior-treesBT_BB_BTTaskBTServiceBT_BB_AAIControllergame-aiMoveToBB_TargetActorLastKnownLocationbIsInvestigatingBT_AAIControllerRunBehaviorTree(BT)TargetActorSucceededFailedInProgressMoveTovoid AEnemyAIController::OnPossess(APawn* InPawn)
{
Super::OnPossess(InPawn);
if (BehaviorTree) // UPROPERTY(EditAnywhere) TObjectPtr<UBehaviorTree>
RunBehaviorTree(BehaviorTree); // initializes & uses the Blackboard the BT references
}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: BothTargetActorvoid 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.RunBehaviorTreeMoveToInProgressFinishLatentTaskSetValueAsObject("Taget", ...)FBlackboardKeySelectorUBTTaskNodeExecuteTaskEBTNodeResultFBlackboardKeySelectorreferences/custom-bttask.mdhttps://dev.epicgames.com/documentation/en-us/unreal-engine/behavior-trees-in-unreal-enginegame-aiunreal-cpp-gameplayfps-shootertower-defense