How to test if a position is in Navmesh?

I searched on forum and it says that UNavigationSystem::ProjectPointToNavigation() is the function to check if a position is in NavMesh, but when put a Cube that Scale is 20.f at location(2000.f, 2000.f) on my Level, and use test code:


UNavigationSystem* const NavSys = GetWorld()->GetNavigationSystem();
FNavLocation Loc1;
FNavLocation Loc2;
FNavLocation Loc3;
FNavLocation Loc4;
FNavLocation Loc5;
FNavLocation Loc6;

bool rs1 = NavSys->ProjectPointToNavigation(FVector(2000.f, 2000.f, 0.f), Loc1);
bool rs2 = NavSys->ProjectPointToNavigation(FVector(1500.f, 1500.f, 0.f), Loc2);
bool rs3 = NavSys->ProjectPointToNavigation(FVector(1000.f, 1000.f, 0.f), Loc3);
bool rs4 = NavSys->ProjectPointToNavigation(FVector(900.f, 900.f, 0.f), Loc4);
bool rs5 = NavSys->ProjectPointToNavigation(FVector(800.f, 800.f, 0.f), Loc5);
bool rs6 = NavSys->ProjectPointToNavigation(FVector(500.f, 500.f, 0.f), Loc6);

all return value are true, Is there any wrong to use ProjectPointToNavigation? or how to use ProjectPointToNavigation?

Have anyone comes across this problem?

ProjectPointToNavigation doesn’t check if the position is on navmesh. It returns the closest position that is on the navmesh instead.
See this:
https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/AI/Navigation/UNavigationSystem/ProjectPointToNavigation/1/index.html
It returns FVector, not bool.

Yep, you’re right. I have sorted it out with UNavigationSystem::TestPathSync :


UNavigationSystem* const NavSys = GetWorld()->GetNavigationSystem();
APlayerController* PC = GetWorld()->GetFirstPlayerController();
if (!NavSys || !PC)
{
	return;
}

const ANavigationData* NavData = NavSys->GetNavDataForProps(PC->GetNavAgentPropertiesRef());
if (!NavData)
{
	return;
}

FVector TestLoc(1000.f, 1000.f, 0.f);
FPathFindingQuery Query(PC, *NavData, PC->GetNavAgentLocation(), TestLoc);
if (!NavSys->TestPathSync(Query))
{
	return;
}