Omit navmesh under height/within bounding box?

Hey guys, quick question. I have a simple environment comprised of a terrain with a water plane at a certain height. I want to bake a navmesh to the terrain that does not include areas ‘underwater’. Is there a simple way to prevent the navmesh from baking under a certain height or within a rectangular volume that I can bound the ‘underwater’ area with?

(When I put a box around the water and set it to ‘unwalkable’ it only cuts the navmesh along the intersections between the box and the terrain, with the navmesh baking within the mesh.)

Thank you!

Unity 5.2.3f1

As you found out, the nav mesh only makes unwalkable areas directly next to the collider on your unwalkable object. To mask off as much of the area as possible, you need as much of the collider as possible to be touching the area you want to mask.

But, placing a bunch of random objects all over the place and positioning them just right would be a waste of time. What you can do is simply duplicate your terrain and then flatten out the areas you want to have walkable.


By doing this, the two terrains will overlap in all the areas you didn’t flatten out. By setting the 2nd masking terrain to unwalkable, all the overlapping areas will then be excluded from the nav mesh on the 1st terrain. Once the nav mesh is baked, just disable the 2nd terrain.

You can’t just duplicate the terrain by pressing ctrl+d though. Doing this will just create a 2nd terrain with a reference to the same terrain data, so modifying one will modify the other. You can get around this by exporting the heightmap of your terrain and using the heightmap data to create your 2nd one.

I realize this is quite an old question, but with new techniques that have come out I figured this is the perfect spot to post this…

An even better way to do what youre after is to use this tutorial series : Runtime NavMesh Generation - Unity Learn

This will allow you to define volumes for your nav mesh to generate. You have to download some of the scripts, but it is free and extremely handy, especially if youre generating multiple navmeshes or need to generate navmesh at runtime. you can even generate the navmesh on walls or ceilings. Here is an example using the “volume” setting on the navmesh surface.

There is an alternate way in “native” Unity to omit navmesh layers.
Make a flat cube-like thing at water level (say 50) with height of 1. Copy it 49 times as its own child. And make each new cube 1 unit lower. So in the end youll have a pancake pie of 50 layers.
With lowest at 0-1 and highest at 49-50.
Mark upper ones (if you want agent to be able to enter shallow water or cross small rivers) walkeble, say ones from 50 to 48.
And all others 47-0 mark unwalkable, Bake.
Dont forget to make a prefab of this cube pencake. Itll save you alot of time in later projects.

Not sure if this was available when @SergeantBiscuits asked the question (probably not), but the right way to achieve this is to mark the areas you don’t want to have a navmesh generated as ‘Not Walkable’.
103427-notwalkable.jpg

In your case, marking the water plane (or any plane that you make at the water height as Not Walkable should do it.)

for anybody looking for an answer in 2022

make a big cube where you dont want any navmesh to be

add nav mesh obstacle to cube

check carve on nav mesh obstacle

make sure the cube isnt navigation static or the nav mesh will spawn on top of the cube