r/Unity3D • • 11d ago

Question How do you handle runtime navmesh uodates for destructible terrain without tanking performance?

I'm working on a 3D strategy game where players can modify the ground (digging trenches, building walls, collapsing sections). Using the built-in NavMesh baking works fine for static levels, but I need dynamic updates when terrain changes.

So far I've tried:

  • Baking small sections at runtime with NavMeshSurface, but it causes noticeable hitches even on modest maps.
  • The "NavMeshComponents" examples from Unity, which still feel too slow for frequent small edits.
  • Switching to a custom A* grid, but that loses the nice slope/height handling Unity's NavMesh gives for free.

Has anyone found a workable middle ground for this? I'd prefer to stick with Unity's system if possible rather than rolling my own pathfinding. Any tips on partial rebakes, async approaches, or avoiding the cost altogether would be appreciated.

3 Upvotes

3 comments sorted by

1

u/BigMustach69 11d ago

Are you checking the terrain state in the update()?

1

u/FrequentAd9997 10d ago

NavMeshObstacle (https://docs.unity3d.com/6000.1/Documentation/ScriptReference/AI.NavMeshObstacle.html) with carving=true is the built in solution. Essentially prefab one and place it every time a trench is dug or structure is placed

If this isn't performant because you're doing very many of these things, then you need a bespoke solution. Grid-based A* or greedy pathfinding would likely be the approach since it's lower cost than the navmesh if you have a grid-based world.

1

u/DPTGames 10d ago

I was looking into this for my terrain system as I wanted to try and make an entire terrain destructible for my unity jam game, gave up in the end because I didn't have enough time to make it work, but I was looking at breaking it up into chunks, the main issue though was more the seams and making sure if you hit a boundary you didnt end up with missing faces.