Search Unity

How to bake invisible "NavMeshObstacle" in NavMesh?

Discussion in 'Navigation' started by Peter77, Sep 20, 2017.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,619
    I have a many static "invisible areas" in a scene that must not be Walkable by NavMeshAgent's. So far I use the NavMeshObstacle Component to carve the NavMesh in these areas.

    Recently I figured out that NavMeshObstacle causes suboptimal NavMesh triangulation, which comes with a measurable performance overhead while agents traverse the environment. I would like to get rid of this performance impact, because the objects are static and could be baked in the NavMesh itself, thus no need for a NavMeshObstacle in the first place.

    Unfortunately, I haven't figured out how to bake invisible areas in a NavMesh. My initial thought was to use a static collider for that purpose, but that didn't work. It seems the NavMesh generation considers objects with a MeshRenderer only.

    How can I bake invisible areas, objects without a MeshRenderer, in a NavMesh?

    I'm using Unity 2017.1.1p2
     
    Last edited: Sep 20, 2017
  2. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    Have you tried using a NavMeshModifier and set to "Ignore From Build" flag?
     
    Peter77 likes this.
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,619
    I did now, thanks for the hint! :)

    After a bit of testing, I found the NavMeshModifierVolume is doing what I want. Unfortunately, the NavMesh Components are not part of Unity 2017.1, but available via GitHub and still experimental or beta. It's too risky for me to use it in the project.

    I found a workaround though, inspired by the NavMeshModifierVolume, plus it's achievable with Unity 2017.1 (and earlier) built-in functionality. Here is the workaround I came up with...

    One time setup

    • Add a new Layer and name it "NavMesh Volume"
    • Untick all "NavMesh Volume" checkboxes in Physics Settings
    • Exclude "NavMesh Volume" Layer from cameras "Culling Mask", so geometry on this layer isn't rendered to the Game View.
    In order to add an invisible "Not Walkable" area to the NavMesh, you have to...
    GameObject setup
    • Create GameObject (eg Cube, Sphere, etc)
    • Set Layer to "NavMesh Volume"
    • Set Tag to "Editor Only"
    • Set NavMesh Area flags to "Not Walkable"
    This causes the "NavMesh Volume" to get baked in the NavMesh and due to the "Editor Only" tag, these objects are removed from the build as well. It still requires a MeshRenderer to work though, but it's good enough for my purpose now.

    In order to hide the "NavMesh Volumes" from the Scene View, you can use the "Layers" drop-down menu in the Editor Toolbar.
     
    Last edited: Sep 21, 2017
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,983
    Actually they are in Unity, they are called NavMeshBuilder now.
     
    Peter77 likes this.
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,619
    I can't find any Component other than "Nav Mesh Agent" and "Nav Mesh Obstacle" in the "Add Component" menu in Unity 2017.1.1p2. What version do you use?

    Is NavMeshBuilder perhaps the scripting API only from the GitHub project, but Components have not been integrated in Unity yet?
     
  6. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    I don't think those are in beta, most of the low level api is integrated into Unity 2017 already afaik, just some components are not and I hope that most of them stay open source so you can make your own version of them, like LocalNavMeshBuilder or NavMeshSourceTag etc.

    Navigation is a wide field and different games have lot's of different needs, so I think it's vital to keep some of stuff as open and configureable as possible.