# Get NavMesh edges

**URL:** <https://forums.unrealengine.com/t/get-navmesh-edges/296775>\
**Category:** AI\
**Tags:** Navigation, edge, unreal-engine, navmesh, question\
**Created:** [October 21, 2014, 3:08am UTC](https://forums.unrealengine.com/t/get-navmesh-edges/296775 "2014-10-21T03:08:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aussiemandias](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aussiemandias](https://forums.unrealengine.com/u/Aussiemandias)\
**Post date:** [October 21, 2014, 3:08am UTC](https://forums.unrealengine.com/t/get-navmesh-edges/296775/1 "2014-10-21T03:08:14Z")

</div>

Hi guys, I’m trying to implement a cover system for my AI. I used to do this by getting the edges of the navmesh (eg. the vertice that stops before the wall/obstacle) and iterate through those until I found an appropriate one.

Is there any way I can get this in the code, I couldn’t find anything related to it in the code.

Thanks, much appreciated.

---

<div class="post-metadata">

**Author:** ![Frozenfire](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Frozenfire](https://forums.unrealengine.com/u/Frozenfire)\
**Post date:** [March 22, 2015, 4:25pm UTC](https://forums.unrealengine.com/t/get-navmesh-edges/296775/2 "2015-03-22T16:25:59Z")

</div>

I’m looking for this as well… am bumping this in hope that someone could answer

---

<div class="post-metadata">

**Author:** ![TooManyCrashes](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TooManyCrashes](https://forums.unrealengine.com/u/TooManyCrashes)\
**Post date:** [August 31, 2016, 5:28pm UTC](https://forums.unrealengine.com/t/get-navmesh-edges/296775/3 "2016-08-31T17:28:48Z")

</div>

This would be very useful. I’m bumping this too.

---

<div class="post-metadata">

**Author:** ![PasteDog](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PasteDog](https://forums.unrealengine.com/u/PasteDog)\
**Post date:** [September 9, 2016, 3:29pm UTC](https://forums.unrealengine.com/t/get-navmesh-edges/296775/4 "2016-09-09T15:29:37Z")

</div>

Hey guys,

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

Here you can find Rama’s way to get the navmesh edges in code.

Hope this helps 🙂  
Elias

---

<div class="post-metadata">

**Author:** ![vipeout](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@vipeout](https://forums.unrealengine.com/u/vipeout)\
**Post date:** [September 9, 2020, 6:49am UTC](https://forums.unrealengine.com/t/get-navmesh-edges/296775/5 "2020-09-09T06:49:24Z")

</div>

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.
}
```

---

<div class="post-metadata">

**Author:** ![shipster](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@shipster](https://forums.unrealengine.com/u/shipster)\
**Post date:** [September 9, 2020, 3:53pm UTC](https://forums.unrealengine.com/t/get-navmesh-edges/296775/6 "2020-09-09T15:53:51Z")

</div>

I would suggest to look into EQS.

In the given case you could find the highest rated position for the NPCs by running some tests for “NPC visibility to the player”. You could find a good cover this way.

Also, you could run a test that finds the edges of the navmesh by looking for the furthest point from the querier (in this case the NPC) which are still reachable via pathfinding (there is also a test for this).

EQS is still exeprimental (but has been for many years) and you have to activate it via Editor Preferences → General → Experimental → Environment Querying System.

You have to use it in combination with behviour trees to use its full potential, but it is not as complicated as it seems.
