Search Unity

Question Update parts of a baked NavMeshSurface at runtime

Discussion in 'Navigation' started by Royall, Jan 18, 2021.

  1. Royall

    Royall

    Joined:
    Jun 15, 2013
    Posts:
    120
    Hello!

    I have been searching and trying for days but I am a little stuck. I am using the Unity NavMeshComponents from Git and I have a NavMeshSurface for my game world.

    I really like to pre-bake the navmesh in the editor. This will function as a base map and will be mostly terrain.
    What also works really well for dynamic objects is the NavMeshObstacle which does its job carving out simple shapes.

    Now what I really miss is the ability to recalculate only a part of the existing navmesh so I can spawn in more complex geometry.

    I know we can access the API and run:
    Code (CSharp):
    1. nm.UpdateNavMesh(nm.navMeshData);
    The issue is that it is really slow at runtime because it is probably recalculating all dynamic objects (also the ones that were calculated before).

    Anyone that could help me out?
     
  2. WillCrate

    WillCrate

    Joined:
    May 16, 2016
    Posts:
    15
    Have you tried calling UpdateNavMesh everytime a change happens? I construct a navmesh at runtime then call UpdateNavMesh. Then everytime I add in any other kind of NavMeshModifier/NavMeshModifierVolume, I call it again. Each of those subsequent calls have resulted in less of a performance hit as it appears to just recalculate the nav mesh for that specified tile of it.

    I essentially set a bool to true if I spawned something that needs the nav mesh updated then in a single manager's LateUpdate I check that bool. If its true I call UpdateNavMesh. That way I only call it once per frame instead of per every object.