AAIController::RunBehaviorTree
#include "AIController.h"
Access: public
Specifiers: virtualUFUNCTIONBlueprintCallable
Description
Starts executing the given Behavior Tree asset on this controller. Returns true if the tree was successfully started; false if it failed (e.g., no BrainComponent could be created, or the asset is null).
Caveats & Gotchas
- • Requires a UBehaviorTreeComponent (a subclass of UBrainComponent) to be present; the component is created automatically if missing, but only on the server — calling this on a client-only controller will fail silently and return false.
- • If a different Behavior Tree is already running, it is stopped and the new one starts from the root. In-flight tasks are aborted and their Finish callbacks fire, which can cause unexpected side-effects if BT logic relies on clean shutdown sequences.
- • UseBlackboard must be called before RunBehaviorTree if the tree references a Blackboard; otherwise keys will be unbound and tasks reading them will see invalid values.
Signature
virtual bool RunBehaviorTree(UBehaviorTree* BTAsset) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| BTAsset | UBehaviorTree* | The Behavior Tree asset to start executing. | — |
Return Type
bool Examples
Run a behavior tree after validating the asset on BeginPlay
Blueprint
Start a behavior tree on possession C++
void AMyAIController::OnPossess(APawn* InPawn)
{
Super::OnPossess(InPawn);
if (BehaviorTreeAsset)
{
UBlackboardComponent* BB = nullptr;
UseBlackboard(BehaviorTreeAsset->BlackboardAsset, BB);
RunBehaviorTree(BehaviorTreeAsset);
}
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?