Hello, Im trying to create my own BTTask thats sets an blackboard vector key to a random point in the nav mesh.
(Like the blueprint node to obtain a random point)
I did succesfully created an blueprint based task wich uses the GetRandomReachablePoint, But when im trying to do the same in c++ I always ending up in an editor crash as soon as I hit the play button.
Could some one point me to the right direction how to do this in c++, Or I just might over see a very simple thing. But yea I have no clue at the point.
EBTNodeResult::Type UTask_GetRandomLocation::ExecuteTask(UBehaviorTreeComponent & OwnerComp, uint8 * NodeMemory)
{
AAIController* AIController = OwnerComp.GetAIOwner();
APawn* ControlledPawn = OwnerComp.GetAIOwner()->GetPawn();
UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
FVector PawnLocation = ControlledPawn->GetActorLocation();
UNavigationSystem NavigationSystem;
FNavLocation NavLoc;
if (NavigationSystem.GetRandomReachablePointInRadius(PawnLocation, Radius, NavLoc))
{
FVector NewLocation = NavLoc;
BlackboardComp->SetValueAsVector(Key_RandomLocation.SelectedKeyName, NewLocation);
return EBTNodeResult::Succeeded;
}
else
{
BlackboardComp->ClearValue(Key_RandomLocation.SelectedKeyName);
return EBTNodeResult::Failed;
}
}