Annoying compiler problem.
I’m making the following call:
bool APlayerPawn_Base::GetIsLocationPathable(const FVector Location) const
{
// Look for a pathable location near the provided location
FNavLocation NearestPathableLocation;
FNavAgentProperties NavAgent = FNavAgentProperties(BodyComponent->GetScaledCapsuleRadius(), (BodyComponent->GetScaledCapsuleHalfHeight() * 2.0f) + BodyComponent->GroundClearance);
bool ProjectionSucceeded = GetWorld()->GetNavigationSystem()->ProjectPointToNavigation(Location, NearestPathableLocation, FVector::ZeroVector, NavAgent, 0);
...
The compiler is complaining at me, saying this:
Error C2664 ‘bool UNavigationSystem::ProjectPointToNavigation(const FVector &,FNavLocation &,const FVector &,const ANavigationData *,FSharedConstNavQueryFilter) const’: cannot convert argument 1 from ‘const FVector’ to ‘UObject *’
Which doesn’t make any sense. Why is it trying to convert argument 1 from const FVector to a UObject* when the function definition it’s even giving in its own error that argument 1 is a const FVector?
The problem presumably has something to do with this function having three definitions:
static FVector ProjectPointToNavigation(UObject* WorldContext, const FVector& Point, ANavigationData* NavData = NULL, TSubclassOf<UNavigationQueryFilter> FilterClass = NULL, const FVector QueryExtent = FVector::ZeroVector);
bool ProjectPointToNavigation(const FVector& Point, FNavLocation& OutLocation, const FVector& Extent = INVALID_NAVEXTENT, const FNavAgentProperties* AgentProperties = NULL, FSharedConstNavQueryFilter QueryFilter = NULL)
bool ProjectPointToNavigation(const FVector& Point, FNavLocation& OutLocation, const FVector& Extent = INVALID_NAVEXTENT, const ANavigationData* NavData = NULL, FSharedConstNavQueryFilter QueryFilter = NULL) const;
Obviously, I’m trying to call the second one, since that’s the version my arguments match. But for some reason, it looks like the compiler thinks I’m trying to call the first, static version, since it’s the only one with a UObject* as the first argument. But the compiler knows I’m trying to call the second one, because that’s the declaration it’s showing in the error?
Does anyone know of a way to resolve this ambiguity? Am I missing something that causes the compiler to get confused by my call? (All versions of the function are public, in NavigationSystem.h)