Search Unity

Updating navmesh at runtime

Discussion in 'Navigation' started by Seregone, Feb 21, 2019.

  1. Seregone

    Seregone

    Joined:
    Nov 4, 2018
    Posts:
    13
    Hello eveyrone,

    I have a problem to update my navmeshsurface at runtime.
    Basically, i have a environment that is bake in editor. In game, player can craft structure and place them on floor. Everything is working except that i don't succeed to update my navmesh.
    When i try to call "surface.BuildNavMesh()", Unity3D simply totally freeze, even if i call this method in a coroutine.
    What should I do ?

    Thank you, have a nice day
     
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    BuildNavMesh is an editor-only function. You can't use it at runtime.
    You can put NavMeshObstacle components on your buildings and set them to carve the NavMesh.
    If you use that together with the NavMesh Components found here instead of the older built-in NavMeshes, they should update properly whenever you add a new building.
     
  3. Bl4ckh34d

    Bl4ckh34d

    Joined:
    Apr 19, 2018
    Posts:
    47
    Hi,

    How can I do the opposite? I have a voxel map and when I destroy a block, I want to be able to update the NavMesh so the tile below the destroyed block is now accessible.
     
  4. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    I don't think using default Navmeshes is the way to go if you're making a voxel map at all.
    You'll probably have to roll your own solution. Good luck.
     
  5. Bl4ckh34d

    Bl4ckh34d

    Joined:
    Apr 19, 2018
    Posts:
    47
    Actually the way I made it work was to create the NavMeshSurface for my whole map and setting up my blocks as NavMeshObstacles and static. Now it works perfectly.