I have a Unity terrain where I painted several paths. I want these paths to have a different area cost than other parts of the terrain.
How can I do this?
I have a Unity terrain where I painted several paths. I want these paths to have a different area cost than other parts of the terrain.
How can I do this?
If they are painted, you can’t - you need Meshes because the NavMesh only cares about Meshes (and Colliders) and not about textures.
You can create a Mesh along your path (or build it with cubes, they won’t be visible in the game and won’t collide with anything) and set the Surface Type to something like “easy to walk” instead of the usual “walkable” - then reduce the area cost. Bake. Done.
Hi, I know this is an old thread, but I came across it whilst looking for this exact issue so I thought it appropriate to add it.
I couldn’t find any solutions that didn’t involve creating meshes, which seemed really not great, so I made my own.
It involves using the NavMeshSurface from the NavMesh building components ( Home Page. | AI Navigation | 1.1.5 )along with auto generated NavMeshModifierVolumes
If you add NavMeshSurface on your terrain, then use NavMeshModifierVolume on objects you place you can modify the cost of an area on the navmesh as you desire at that point. The problem is you have to manually place all your volumes by hand which is a pain, So I wrote a script that samples the terrain texture in a grid across the entire terrain and at each point creates a cube volume for that cost, then rebuilds the mesh, and done…
Only issue I’ve come across is that the Off mesh links are no longer generated automatically… A small price to pay…
GIST for the component is here (it even handles terrain based trees by marking them as nonwalkable):
** Hi, this is an edit. Do note, that this GIST here is NOT optimized for large terrains, and Unity will NOT be happy if you attempt this on large terrain. If you must use it on large terrain set step to 10 or 100 or comment out line 139. Line 139 will delete the nav hint boxes, if you leave them then you can edit the nav hint boxes to fit better, then use Bake in the NavMeshSurface. **
Add the component on your terrain, adjust the layer if needed, add the areaIDs (eg, Walkable, Path, Not Walkable) that match the textures on your terrain (eg, Grass texture, path texture, slime texture) add a NavMeshSurface and trigger the GenMeshes function ( my version uses Odin for the button but feel free to remove that and make your own inspector or whatever that regenerates onValidate ). Note that you should NOT use BAKE button in either the global navmesh OR the NavMeshSurface component.
Image example:
Thank You this was very helpful…
Hello, I know this is an old thread. But I got a problem when trying to make a specific area to have lower cost using NavMeshModifierVolume.
The problem is that area will absolutely separate from others. And I can’t navigate/caculatepath into that area anymore.
I also found that this is not a case in build-in navigate system unity. This is only happend when I use navigate component to bake navmesh.
Can someone help me please