In my code of BehaviorTree task node, I used GetRandomPointInNavigableRadius() to get vector point where a npc move to.
below is some of my code.
EBTNodeResult::Type UBTTask_FindPatrolPos::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
EBTNodeResult::Type Result = Super::ExecuteTask(OwnerComp, NodeMemory);
ABLOG_S(Warning);
auto ControllingPawn = OwnerComp.GetAIOwner()->GetPawn();
if (nullptr == ControllingPawn)
{
ABLOG_S(Warning);
return EBTNodeResult::Failed;
}
UNavigationSystemV1* NavSystem = UNavigationSystemV1::GetNavigationSystem(ControllingPawn->GetWorld());
if (nullptr == NavSystem)
{
ABLOG_S(Warning);
return EBTNodeResult::Failed;
}
FVector StartPos = ControllingPawn->GetActorLocation();
FNavLocation NextPatrol;
**if (NavSystem->GetRandomPointInNavigableRadius(StartPos, 500.0f, NextPatrol))**
{
OwnerComp.GetBlackboardComponent()->SetValueAsVector(AABAIController::PatrolPosKey, NextPatrol.Location);
return EBTNodeResult::Succeeded;
}
return EBTNodeResult::Failed;
}
On “if (NavSystem->GetRandomPointInNavigableRadius(StartPos, 500.0f, NextPatrol))”, it always returns false
and the PatrolPosKey’s value is set to invalid so that the npc does not move.
How can I make the PatrolPosKey’s value valid?