Search Unity

Including invisible objects into navmesh baking

Discussion in 'Navigation' started by neginfinity, Apr 5, 2015.

  1. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    7,102
    When baking navmesh, how can I include invisible objects into process?

    If I make a cube, set it to "navigation static", disable "mesh renderer" component and attempt to bake navmesh, the cube is ignored, unless I re-enable "mesh renderer" component.

    How can I change that behavior? I'd like to keep some objects hidden AND include them into navmesh baking.


     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Make sure that you don't disable the game object, but only the mesh renderer. Like that, the game object including the BoxCollider will still be active and considered for the NavMesh calculation.
     
  3. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    7,102
    Here is object configuration (see panel on the right). Object enabled, mesh renderer disabled, collider enabled. The object is ignored by mesh baking system. What am I missing?


    I COULD put alpha-test shader on it and throw 1x1 pixel texture with 0 alpha, but it is kinda silly (because graphical subsystem would still attempt to "draw" it). Is there a better way to do it?


    ---EDIT---


    Ugh... googled a bit and found couple of other quesitons mentioning this "feature":
    http://forum.unity3d.com/threads/script-baking-navmeshes-for-hidden-objects.128345/
    http://answers.unity3d.com/questions/421030/how-to-generate-a-navmesh-only-with-colliders.html

    It looks like navmesh ignores anything that does not have mesh renderer, and the only way to fix it is to temporarily enable renderers before navmesh baking.

    Guess I'll need to write another script.
     
    Last edited: Apr 5, 2015
  4. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    7,102
    I've solved the problem by making a script that temporarily makes invisible colliders visible and then bakes navmesh. There doesn't seem to be any other way to do it.
     
  5. graciasluigi

    graciasluigi

    Joined:
    Feb 11, 2015
    Posts:
    12
  6. Shbli

    Shbli

    Joined:
    Jan 28, 2014
    Posts:
    126
    You can add a script to destroy that when the game run

    Dependin on what you need, in start methode, you can call "Destroy(gameObject)" or "Destroy(GetComponent<MeshRenderer>())"

    That will save some performance for you if you don't need the component when the game runs

    I have a lot of hidden boxes that they auto destroy themselves when the game runs
     
  7. Lahzar

    Lahzar

    Joined:
    May 6, 2013
    Posts:
    87
    Either prebake the navmesh and destroy all the objects. I guess you could do this in unity. Pretty much what @Shibli suggested.

    Have you tried going to the meshrenderer and setting cast shadows to shadows only? If not you could also put all the objects on their own layer and make no camera render it, or give them all carving navmeshobstacles. But the first solution is more efficient.

    Worst case scenario, change pathfinding solutions. #A*MasterRace
     
  8. SashaMartysh

    SashaMartysh

    Joined:
    Dec 13, 2015
    Posts:
    4
    If you don't need to bake anyway, you may use adding a "Nav Mesh Obstacle" component to your object. This component also adds a hole to walkable area around the object when "Carve" is checked.
     
    Cover-Club-Media likes this.
unityunity