Search Unity

5.6 Nav - Modifying nav mesh at runtime and tile size

Discussion in 'Navigation' started by pablishoRM, Apr 27, 2017.

  1. pablishoRM

    pablishoRM

    Joined:
    Apr 27, 2017
    Posts:
    3
    Hi all,

    I'm working on a scene where nav mesh is updated after the user add objects to it. I start with a plane and add cubes to it. The nav mesh should be updated by restricting the navigation of the plane because of the new obstacle, and a new nav mesh should be generated on top of the cube. But I found that if my new object is placed inside a tile, the new nav mesh for the cube is not generated, while if I place it "breaking" the tiling (so the cube is in two tiles) then the nav mesh is generated. Is this the expected behaviour or is it a bug? I could reduce the tiling, but that's not what I want actually. I add some pictures to explain it better.

    I'm using NavMeshBuilder.UpdateNavMeshDataAsync() in the same way it's being used in LocalNavMeshBuilder in the examples in https://github.com/Unity-Technologies/NavMeshComponents

    Here the nav mesh is not generated for the box:

    Screen Shot 2017-04-27 at 12.57.04 PM.png

    Here the nav mesh is generated for the second box because it's between two tiles:

    Screen Shot 2017-04-27 at 12.57.23 PM.png
     
  2. Jakob_Unity

    Jakob_Unity

    Joined:
    Dec 25, 2011
    Posts:
    269
    From the docs ( https://docs.unity3d.com/Manual/nav-AdvancedSettings.html )

    The NavMesh is built in parallel as a grid of tiles. If an area straddles a tile boundary, the area is not removed. The reason for this is that the area pruning happens at a stage in the build process where surrounding tiles are not accessible.
     
  3. pablishoRM

    pablishoRM

    Joined:
    Apr 27, 2017
    Posts:
    3
    Thanks!

    I actually don't want it to be removed. So the problem seems to be that my object is smaller than the "Min Region Area". Is the "Min Region Area" the same as the tile size? Or how can I control it when baking at runtime?
     
  4. Jakob_Unity

    Jakob_Unity

    Joined:
    Dec 25, 2011
    Posts:
    269
    hmm seems to be not exposed to runtime navmesh building for no obvious reason .. an ommision on my part - sry..
    I'll try to patch this asap ..

    In the meantime - if you need a workaround you can use reflection to set the min. region area:

    Code (csharp):
    1.  
    2. using System.Reflection;
    3.  
    4. ...
    5. // assuming the 'buildSettings' variable is available here
    6.  
    7. // Warning : nasty, dirty reflection kludge here
    8.   var t = typeof (UnityEngine.AI.NavMeshBuildSettings);
    9.   object boxedSettings = new UnityEngine.AI.NavMeshBuildSettings();
    10.   boxedSettings = buildSettings;
    11.   t.GetField ("m_MinRegionArea", BindingFlags.NonPublic | BindingFlags.Instance).SetValue (boxedSettings, 0.0f);
    12.   buildSettings = (NavMeshBuildSettings)boxedSettings;
    13.  
    14. // 'buildSettings' has min region area of 0
    15. ...
    16.  
    17.  
     
  5. pablishoRM

    pablishoRM

    Joined:
    Apr 27, 2017
    Posts:
    3
    Thank you!

    I'll use that workaround but I'm looking forward that patch.
     
  6. cdolese

    cdolese

    Joined:
    Feb 7, 2017
    Posts:
    1
    Hey there, was this issue ever patched?