SokPapa
(SokPapa)
September 24, 2022, 1:02pm
1
I am trying to get the Actor Location but I am getting the “[C2352] ‘AController::GetPawn’: illegal call of non-static member function” error.
I am brand new in C++, what I am missing?
EBTNodeResult::Type UBTTask_GetRandomLocation::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
auto PawnLocation = AController::GetPawn()->GetActorLocation();
auto BlackBoard = OwnerComp.GetBlackboardComponent();
auto NavLocation = new FNavLocation();
UNavigationSystemV1::GetRandomPointInNavigableRadius(PawnLocation, 1000, *NavLocation);
FName BB_Target = "TargetPosition";
BlackBoard->GetValueAsVector(BB_Target) = NavLocation->Location;
return EBTNodeResult::Succeeded;
}
3dRaven
(3dRaven)
September 24, 2022, 1:34pm
2
It seems GetPawn() is not a static method. You probably need to pass in a controller instance and then call ->GetPawn() on it.
Tuerer
(Tuerer)
September 24, 2022, 2:45pm
3
You’re trying to call the function of an abstract class, whereas you need to call the function of a concrete instance of the controller.
You need to get the reference to the actual controller first.
SokPapa
(SokPapa)
September 24, 2022, 3:19pm
4
My question was misleading, sorry about it.
since it is a task for BehaviourTress, I need to reach the Pawn from the OwnerComp.GetOwner(), not from a concrete class.
My knowledge of Unreals API is limited atm. Do you have an idea how can I do it?
SokPapa
(SokPapa)
September 24, 2022, 3:24pm
5
I don’t need the Pawn, instead I can Use
OwnerComp.GetOwner()->GetActorLocation();