Hello!
I ran into a weird bug where a behaviour tree basically gets stuck in the MoveTo node, despite the character actually reaching the destination. I use a custom BP AIController class that is derived from a custom c++ class that inherits from the default AAIController. In my BaseAIController, I do the following in OnPossess():
void ABaseAIController::OnPossess(APawn* InPawn)
{
Super::OnPossess(InPawn);
if (!InPawn) return;
// Get the behaviour tree and patrol route from the possessed pawn
if (ABaseEnemy* Enemy = Cast<ABaseEnemy>(InPawn);
Enemy)
{
// Get Behaviour Tree Asset
BehaviorTreeAsset = Enemy->GetBehaviourTree();
if (!BehaviorTreeAsset)
{
UE_LOG(LogAI, Error, TEXT("Behaviour Tree is not set in the Enemy Class!"));
return;
}
PatrolPoints = Enemy->GetPatrolPoints();
if (PatrolPoints.Num() == 0) UE_LOG(LogAI, Warning, TEXT("Possessed enemy doesn't have a patrol route."));
}
if (!BehaviorTreeAsset->BlackboardAsset)
{
UE_LOG(LogAI, Error, TEXT("Behavior Tree has no blackboard assigned!"));
return;
}
if (!BlackboardComp)
{
BlackboardComp = NewObject<UBlackboardComponent>(this);
BlackboardComp->RegisterComponent();
}
if (!UseBlackboard(BehaviorTreeAsset->BlackboardAsset, BlackboardComp))
{
UE_LOG(LogAI, Error, TEXT("Failed to use Blackboard!"));
return;
}
if (!BehaviorTreeComp)
{
BehaviorTreeComp = NewObject<UBehaviorTreeComponent>(this);
BehaviorTreeComp->RegisterComponent();
}
BehaviorTreeComp->StartTree(*BehaviorTreeAsset);
}
After some debugging, I figured out that the issue wouldn’t occur if I called RunBehaviourTree in BP’s OnPossess(). Is there anything wrong with my OnPossess that causes the MoveTo to fail?