# AI Tasks with MoveTo do not wait for move to complete

**URL:** <https://forums.unrealengine.com/t/ai-tasks-with-moveto-do-not-wait-for-move-to-complete/410729>\
**Category:** Blueprint\
**Tags:** unreal-engine, CPP, Blueprint, question\
**Created:** [November 27, 2017, 5:15pm UTC](https://forums.unrealengine.com/t/ai-tasks-with-moveto-do-not-wait-for-move-to-complete/410729 "2017-11-27T17:15:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_5f828679](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5f828679](https://forums.unrealengine.com/u/anonymous_user_5f828679)\
**Post date:** [November 27, 2017, 5:15pm UTC](https://forums.unrealengine.com/t/ai-tasks-with-moveto-do-not-wait-for-move-to-complete/410729/1 "2017-11-27T17:15:17Z")

</div>

Hello,

I’m having a problem getting my AI to move properly. What seems to be happening is that the AI doesn’t wait for the MoveTo() task to finish before moving on. I’ve included my C++ method below that runs the task. I built the blackboard and behavior tree in the editor and only switched to C++ for this single task.

I also have the same problem with the MoveToLocation node in blueprints. Am I just missing some sort of thread lock call?

Thanks!

```
EBTNodeResult::Type UFilmCarTask::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) {
	m_blackboard = OwnerComp.GetBlackboardComponent();
	AStaticMeshActor* Car = dynamic_cast<AStaticMeshActor*> (m_blackboard->GetValueAsObject("CarToFilm"));

	FVector CarLoc = Car->GetActorLocation();
	FBox CarBounds = Car->GetComponentsBoundingBox();

	AAIController* AI_con = OwnerComp.GetAIOwner();
	APawn* AI_pawn = AI_con->GetControlledPawn();
	FVector CameraLoc = AI_pawn->GetActorLocation();

	FVector ClosePoint = CarBounds.GetClosestPointTo(CameraLoc);
	FVector* Path = 0;
	genPath(CarBounds, ClosePoint, Path);
	
	EPathFollowingRequestResult::Type result;
	for (UINT i = 0; i < 60; ++i) {
		FAIMoveRequest moveTarget(Path[i]);
		moveTarget.SetAcceptanceRadius(10.0f);
		result = AI_con->MoveTo(moveTarget);
	}
	delete[] Path;

	if (result == EPathFollowingResult::Type::Success) return EBTNodeResult::Succeeded;
	
	

	return EBTNodeResult::Failed;
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5f828679](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5f828679](https://forums.unrealengine.com/u/anonymous_user_5f828679)\
**Post date:** [November 28, 2017, 9:48pm UTC](https://forums.unrealengine.com/t/ai-tasks-with-moveto-do-not-wait-for-move-to-complete/410729/2 "2017-11-28T21:48:38Z")

</div>

Ok, so with some more searching, I’ve found that when it comes to blueprints, they suggest you add nodes in the task blueprint to check when the pawn gets to its destination. However, what seems to me as the obvious C++ analogy locks up the editor.

```
while (AI_con->GetMoveStatus() == EPathFollowingStatus::Type::Moving) {}

```

So that’s no good. I’ve seen that in BTTask\_MoveTo.cpp there appears to be a messenger service.

```
		result = AI_con->MoveTo(moveTarget,&outPath);
		if (result.Code == EPathFollowingRequestResult::RequestSuccessful){
			WaitForMessage(OwnerComp, UBrainComponent::AIMessage_MoveFinished, result.MoveId);
			WaitForMessage(OwnerComp, UBrainComponent::AIMessage_RepathFailed);
			NodeResult = EBTNodeResult::InProgress;
			UE_LOG(LogTemp, Warning, TEXT("Request Successful!"));
		}

```

But that doesn’t force the ExecuteTask method to wait either.
