# How to use FinishLatentTask()?

**URL:** <https://forums.unrealengine.com/t/how-to-use-finishlatenttask/416850>\
**Category:** AI\
**Tags:** Behavior-Tree, bttask, unreal-engine, UE4, CPP, question\
**Created:** [February 9, 2018, 11:59am UTC](https://forums.unrealengine.com/t/how-to-use-finishlatenttask/416850 "2018-02-09T11:59:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![XynanXDB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@XynanXDB](https://forums.unrealengine.com/u/XynanXDB)\
**Post date:** [February 9, 2018, 11:59am UTC](https://forums.unrealengine.com/t/how-to-use-finishlatenttask/416850/1 "2018-02-09T11:59:38Z")

</div>

HI, everyone. I’m having problem to set a task’s EBTNodeResult from InProgress to Succeeded. I made the AI move to a location when the AI is too close to the player.

```
EBTNodeResult::Type UBTTask_MoveBack::ExecuteTask(UBehaviorTreeComponent & OwnerComp, uint8 * NodeMemory)
{
	AAICharacterController* AICon = Cast<AAICharacterController>(OwnerComp.GetAIOwner());
	FVector AILoc = AICon->GetCharacter()->GetActorLocation();
	FVector NextAILoc;
	if (AICon) {
		UBlackboardComponent* blackboardComp = Cast<UBlackboardComponent>(AICon->GetBlackboardComp());
		AActor* playerKey = Cast<AActor>(blackboardComp->GetValueAsObject("Player"));
		FVector minAndMaxDistance = blackboardComp->GetValueAsVector("minandMaxDistance");
		NextAILoc = AILoc + (AICon->GetCharacter()->GetActorForwardVector() * -1 * 200.0f);

		//x Distance between AI and Player
		//float deltaDistance = FVector::Dist(AICon->GetCharacter()->GetActorLocation(), playerKey->GetActorLocation());
		UKismetSystemLibrary::DrawDebugLine(GetWorld(), AILoc, NextAILoc, FLinearColor::Red, 5.0f, 10.0f);

		AICon->MoveToLocation(NextAILoc);	
	}

	return EBTNodeResult::InProgress;
}

```

But the problem is the Task stays InProgress. Is there anyway to set it to Succeeded when AI reached target location? I found out the FinishLatentTask(), but I dont know when and how to call? Please help, I’m a noob.

---

<div class="post-metadata">

**Author:** ![XynanXDB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@XynanXDB](https://forums.unrealengine.com/u/XynanXDB)\
**Post date:** [February 9, 2018, 12:00pm UTC](https://forums.unrealengine.com/t/how-to-use-finishlatenttask/416850/2 "2018-02-09T12:00:54Z")

</div>

The structure on the code is screwed up a bit because I was desperate trying to figure out how to fix it lel.

---

<div class="post-metadata">

**Author:** ![XynanXDB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@XynanXDB](https://forums.unrealengine.com/u/XynanXDB)\
**Post date:** [February 9, 2018, 3:24pm UTC](https://forums.unrealengine.com/t/how-to-use-finishlatenttask/416850/3 "2018-02-09T15:24:17Z")

</div>

Never mind, I separate the tasks into 2 BTTaskNode, one for Calculating Next AI Location another one for Moving there
