UBTTaskNode adding completion event?

Hey guys, I am attempting to create a custom black board task in C++.
In my Execute task function I successfully do what I want to do, but the function completes instantly.

EBTNodeResult::Type UBTT_MoveToRandomLocation::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	
	FVector randomVector = FMath::VRand();

	randomVector.Normalize();

	randomVector *= FMath::RandRange(MinimumWanderRadius, MaximumWanderRadius);

	UAITask_MoveTo* currentOperation = nullptr;

	switch (WanderMode)
	{
	case EWanderMethod::FromSpecifiedPoint:
		currentOperation = UAITask_MoveTo::AIMoveTo(OwnerComp.GetAIOwner(), m_wanderCenter + randomVector);
		break;
	case EWanderMethod::FromCurrentPoint:
		m_wanderCenter = m_wanderCenter = OwnerComp.GetAIOwner()->GetPawn()->GetActorLocation();
		currentOperation = UAITask_MoveTo::AIMoveTo(OwnerComp.GetAIOwner(), m_wanderCenter + randomVector);
		break;
	case EWanderMethod::FromSpawnPoint:
		currentOperation = UAITask_MoveTo::AIMoveTo(OwnerComp.GetAIOwner(), m_wanderCenter + randomVector);
		break;
	default:
		break;
	}

	return EBTNodeResult::Succeeded;
}

I want to wait until currentOperation is complete before saying my task is done but cannot figure out how to do that outside of introducing a busy wait loop. Any ideas?

Instead of EBTNodeResult::Succeeded you need to return EBTNodeResult::InProgress (or something similar, I’m away from my sources :wink: ). Also, consider returning “failure” result if something goes wrong.

Cheers,

–mieszko

Wouldn’t I just be stuck in InProgress forever then? how does the behavior tree know when the event is ever completed?

You have to setup conditions to tell it when it is completed. I had to setup a custom delay task using a timer. I return InProgress until the timer fires which then returns Succeeded.