RealDocs

AAIController::RunBehaviorTree

function AIModule Blueprint Since 4.0
#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
Event BeginPlay Is Valid Input Object Is Valid Is Not Valid Run Behavior Tree Target is AI Controller Target BT Asset Return Value BT Asset BT Asset
Edit Blueprint graph Run a behavior tree after validating the asset on BeginPlay
Drag node headers to move · Drag from an output pin to an input pin to connect · Scroll to zoom · Right-click for actions
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);
	}
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.