Search Unity

Combining pre-baked NavMeshes

Discussion in 'Navigation' started by Jarko89, Feb 16, 2018.

  1. Jarko89

    Jarko89

    Joined:
    Mar 8, 2017
    Posts:
    15
    Hi guys, I need a little help.

    I'm instantiating terrains at runtime according to the position of the player. Each block is spawned right next to an existing one, of course.

    Each terrain has its own pre-baked NavMesh assigned to it. This NavMesh is added to the general NavMesh as such:

    NavMesh.AddNavMeshData(data);

    Doing that doesn't merge the new NavMesh with the existing one though. If the character approaches a new terrain, he can't walk walk on the NavMesh of that terrain.

    I know of NavMesh links and such, but it looks like their purpose is different. I'm surprised there's no simple way of doing this.

    Thank you!
     
  2. Jarko89

    Jarko89

    Joined:
    Mar 8, 2017
    Posts:
    15
    Bump... Any clue? :)
     
  3. Jarko89

    Jarko89

    Joined:
    Mar 8, 2017
    Posts:
    15
    Bumpety bump!
     
  4. mirkoemirbc

    mirkoemirbc

    Joined:
    Nov 17, 2016
    Posts:
    10
  5. horatiu665

    horatiu665

    Joined:
    Nov 22, 2012
    Posts:
    24
    Using NavMeshSurface.BuildNavMesh() seems to defeat the purpose of pre-baking the navmeshes for each object. I think the point of the OP was to build nav meshes on edit time, which might be the more costly operation, and simply add them procedurally at runtime (the only needed computation is merging the existing navmeshes rather than computing them in full again).

    I am trying to achieve this goal in any case, and adding off mesh links to every side of my precomputed navmesh does not seem like a good way to do it especially since 1. I don't plan to have square meshes, and 2. the agent does not turn the same way on navmesh and on offmesh link, and I don't want them to jump, just traverse normally.
     
  6. nih_

    nih_

    Joined:
    Aug 7, 2017
    Posts:
    8
    Has any of you found a solution for runtime "joining" premade navmeshes?
     
  7. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    I'm pretty certain it's better to simply generate the NavMesh on runtime instead of prebaking, like mirkoemirbc suggested above. The NavMeshBuilder seems to work iteratively and only rebuilds the areas that have changed. If you make sure to also remove faraway tiles no longer used whenever you add new ones, this should keep the performance footprint on a same-ish level.
     
  8. Grizmu

    Grizmu

    Joined:
    Aug 27, 2013
    Posts:
    131
    Official way of doing it from the manual is to use the navmesh links : https://docs.unity3d.com/Manual/nav-AdditiveLoading.html .
    A more advanced navmesh link is also available: https://docs.unity3d.com/Manual/class-NavMeshLink.html

    I admit that the default behaviour feels weird to use, but there is a way to outfit your agents in a custom offmesh link traversal logic : https://docs.unity3d.com/540/Documentation/ScriptReference/NavMeshAgent.CompleteOffMeshLink.html .
    With it you can achieve good results close to having a single navmesh, with no rebaking and other shenanigans required.
     
    GuardHei likes this.