For anyone ever stumbling onto this thread - I’ve had the same problem. I don’t know if it was possible to do it this way in 2014, but it’s possible now (4.25 at least). Works rock solid. Here we go:
UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
INavigationDataInterface* const NavData = NavSys->GetNavDataForActor(*GetOwner());
const ARecastNavMesh* const RecastNavMesh = Cast<const ARecastNavMesh>(NavData);
FRecastDebugGeometry NavMeshTileGeo;
NavMeshTileGeo.bGatherNavMeshEdges = true;
TArray<FVector> PointsToGatherTiles = { CurrentLoc, DesiredLoc };
TSet<int32> AddedTileIndices;
for (const FVector& GatherPoint : PointsToGatherTiles)
{
int32 TileX, TileY;
RecastNavMesh->GetNavMeshTileXY(GatherPoint, TileX, TileY);
TArray<int32> TileIndices;
RecastNavMesh->GetNavMeshTilesAt(TileX, TileY, TileIndices);
for (int32 i = 0; i < TileIndices.Num(); ++i)
{
if (!AddedTileIndices.Contains(TileIndices[i]))
{
RecastNavMesh->GetDebugGeometry(NavMeshTileGeo, TileIndices[i]);
AddedTileIndices.Add(TileIndices[i]);
}
}
}
I know “GetDebugGeometry” sounds like it’s not going to be present in a packaged build, but it is and I’m using it currently in our project.
The code is a bit more complex than it could, only because I need edges for two positions - current and destination. This is only really needed when the positions are on different navmesh tile (the squares that are recalculated asynchronously in editor), but in character movement code (where this is from) such situations occur - at some point you do move in a single frame from tile to tile. If you only need edges for a single point, you can remove the “PointsToGatherTiles” variable and the outer loop. You still need the inner loop, because there will be multiple indices for a single tile.
The condition inside the inner loop if (!AddedTileIndices.Contains(TileIndices[i]))
makes sure you don’t get the same edge added twice, which would happen when both locations are in the same navmeshtile. If you only use a single point, this will never happen, and as such you may also remove that condition.
The final edge data is stored in NavMeshTileGeo.NavMeshEdges
and it is stored in a pair format (each 2 points form an edge) so you need to access it like this:
for (int32 i = 0; i < NavMeshTileGeo.NavMeshEdges.Num(); i += 2)
{
// Use elements i and i+1. This array always contains even number of entries.
}