# BehaviourTree stuck in MoveTo if starting Behaviour Tree from OnPossess() in AIController in c++

**URL:** <https://forums.unrealengine.com/t/behaviourtree-stuck-in-moveto-if-starting-behaviour-tree-from-onpossess-in-aicontroller-in-c/2472679>\
**Category:** AI\
**Tags:** ai-controller, CPP, Blueprint, question\
**Created:** [April 23, 2025, 8:19pm UTC](https://forums.unrealengine.com/t/behaviourtree-stuck-in-moveto-if-starting-behaviour-tree-from-onpossess-in-aicontroller-in-c/2472679 "2025-04-23T20:19:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wortback1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@wortback1](https://forums.unrealengine.com/u/wortback1)\
**Post date:** [April 23, 2025, 8:19pm UTC](https://forums.unrealengine.com/t/behaviourtree-stuck-in-moveto-if-starting-behaviour-tree-from-onpossess-in-aicontroller-in-c/2472679/1 "2025-04-23T20:19:02Z")

</div>

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():

```auto
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?
