Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Nav generating INSIDE non-walkable objects.

Discussion in 'Navigation' started by sigbuserror, Dec 8, 2016.

  1. sigbuserror

    sigbuserror

    Joined:
    Dec 4, 2010
    Posts:
    5
    So I have been working with Unity for a while and have long been unable to figure out a solution to this problem. We have are trying to use the Unity Navigation system but even when an solid object is set to not be walkable it will only cut the nav at the shell of the mesh, resulting in islands hidden inside the objects. This is true even using the basic 3d objects built into Unity. Is there any way to avoid this? I would like to avoid having to switch to a new navigation system just because of this one issue but it is a major deal-breaker.
     

    Attached Files:

    TechRoxx5 likes this.
  2. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,441
    yep a plague of recast. UT's fixing it and with a bit of luck and nagging it'll be in 5.6.
    it's not a deal breaker though, when you spawn, test that it reaches valid points on the navmesh.
     
  3. cyuxi

    cyuxi

    Joined:
    Apr 21, 2014
    Posts:
    49
    The problem is the height of the Non-walkable Object can not be higher than the Agent Height.
    If your agent height is 2, then your Object height cannot larger than 2, otherwise unity wont consider the volume of the object.
    I have tested this with a box, first scale the box a bit larger to get a reasonable volume, then scale it on height(y), and you will see the problem occurs when the height go over the Agent Height.
    I consider this a bug of unity because there is no reason to make a much taller non-walkable object walkalbe inside but the shorter one remains solid... How Ridiculous! o_O:mad:
     
    AlexTheOutsider and erenaydin like this.
  4. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    Perhaps adding NavmeshModifierVolume or NavmeshModifier to your obstacles and set it to unwalkable would be useful. Doesn't suffer from navMeshes being built when too far within the obstacle's collider edges. It would be nice if these could be based of a mesh though, currently just box and cylinder...
     
    idbrii and laurentlavigne like this.
  5. Jakob_Unity

    Jakob_Unity

    Joined:
    Dec 25, 2011
    Posts:
    269
    This is nagging a lot of users - we have plans to add a seed-point what will optionally cull polygons not connected to the seed point. Not coming any time soon - until then i second the modifier volume approach (if the shape fits).
     
  6. Alex_curiscope

    Alex_curiscope

    Joined:
    Apr 4, 2017
    Posts:
    55
    This is sooooo annoying, sorry! My god it just seems like a really basic feature? Why can the nav mesh obstacles only be boxes or capsules? I have a bunch of rocks that are irregularly shaped and I'm getting nav mesh generating on the underlying terrain inside the rocks. Just infuriating.
     
  7. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,441
    It's been a while already, over a year already. What's the hold up?
     
  8. butaca

    butaca

    Joined:
    Jan 13, 2014
    Posts:
    1
    Same issue here. Any news on this? The NavmeshModifierVolume workaround is tedious and time consuming. Thanks.
     
  9. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,441
    Temporary solution: bake mesh using colliders
     
  10. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    4,001
    Unity, been A full year pretty much, a response would be appreciated on this as it is still happening.
     
  11. Alex_curiscope

    Alex_curiscope

    Joined:
    Apr 4, 2017
    Posts:
    55
    The solution is to switch industries to post production - then if you have bugs they'll be falling over their feet to fix it for you :)
     
    patmckenna likes this.
  12. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Would love this, any chance of it happening? Or maybe suggestion for us, as we are trying to make the process as automatic as possible due to small team size.
     
  13. AlejandroDaJ

    AlejandroDaJ

    Joined:
    May 30, 2014
    Posts:
    5
    Still a major issue...
     
  14. bagelbaker

    bagelbaker

    Joined:
    Jun 5, 2017
    Posts:
    67
    We have this issue also, we'd love to have this fixed!
     
  15. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I understand this issue correctly now, it's just the navmesh doesn't really have a volume to it so there will always be the same island inside further down. These areas can be easily checked: assuming your colliders are all convex (they really should be or your game is wasting performance), you can do a sphere overlap check at the destination navmesh. If it collides then you know that destination is inside geometry. This works with convex or primitive colliders because those colliders have volume so the sphere check will register true if inside :)

    Hope that helps, this is no longer an issue for anyone and just poke me with @ if you need more advice, any readers.
     
  16. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    And how to deal with it?

    12.png 21.png
     
  17. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    The reason this happens is because navmeshes are technically 2D, so it's "by design". You need to make your code deal with it, but in reality, an agent will fail to path there and you would have no reason to tell them to go there, right?
     
  18. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    The problem is that my AI have the functions of a free walk. It is implemented using the NavMesh.SamplePosition function, which defines these zones as accessible for walking. I found a solution to the problem, but I have to do a lot of manual work, closing these empty spaces.
     
  19. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yep, don't forget you can raycast the location beforehand (navmesh raycast is 2D and Physics raycast is 3D). Or simply path there and check if it only has a partial path (look at API for this), and can then easily reject it.
     
  20. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    I have already done everything manually 33.png
     
    lc0040 likes this.
  21. GenOli

    GenOli

    Joined:
    Apr 21, 2013
    Posts:
    139
    Nearly 3 years and no fix, this is a travesty...
     
    Ishimine, Griffo, funkyCoty and 6 others like this.
  22. PrimeSoul

    PrimeSoul

    Joined:
    Nov 20, 2017
    Posts:
    2
    This needs a fix asap
     
    Griffo likes this.
  23. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It's not broken if you're wondering, it's just a limitation of the technique with easy workarounds. So technically everyone is asking for a feature.
     
  24. juanfornos

    juanfornos

    Joined:
    Feb 17, 2018
    Posts:
    10
    I have to disagree. A user only cares about the functionality regardless of its implementation and from this point of view, this is broken since it doesn't work as expected. From a user perspective this is a bug.
     
  25. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    275
    I'd be happy if I could post-process the NavMesh myself and manually remove all the regions that are not connected to a reference point, but it seems Unity doesn't give me this opportunity. Am I wrong?
     
  26. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    Afaik you can't do this at the moment. But what you can do is add NavMeshModfier volumes to those houses, which would prevent it from happening.
     
  27. imrankhanswati

    imrankhanswati

    Joined:
    Jul 14, 2016
    Posts:
    5
    That's wright but then we have to use NavMeshSurface which is quit limited compare to the already included Navigation system. So me personally i will stay away from it.
     
  28. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    Hmm really, I thought NavMeshSurface is more advanced and faster than the old system. What do you mean by limited in your case?
     
  29. Frais254

    Frais254

    Joined:
    Oct 26, 2014
    Posts:
    169
    Was something like this ever implemented? This would be extremely useful
     
  30. Frais254

    Frais254

    Joined:
    Oct 26, 2014
    Posts:
    169
  31. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Nice. Unity should build that in.
     
    Griffo and Frais254 like this.
  32. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    He wasn`t kidding.
    3.5 years later and still not fixed.

    I`m spawning enemies with sample position and if there's an island it's possible they get placed on the island and they won't be able to move around.

    Big problem. Guess I'll have to look into the cleaner but it's yet another work around.
     
    scorp2007, eggsamurai and Razputin like this.
  33. eggsamurai

    eggsamurai

    Joined:
    Oct 10, 2015
    Posts:
    119
  34. Frais254

    Frais254

    Joined:
    Oct 26, 2014
    Posts:
    169
    Please give us an update ;__;
     
    Ghat-Smith likes this.
  35. erdostamasa

    erdostamasa

    Joined:
    Mar 28, 2020
    Posts:
    32
    Guess its never coming
     
  36. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    If you're baking in the Editor, you can apply NavMeshModifierVolumes inside the objects that get a NavMesh generated inside them. If you're baking at Runtime, you can use the completed callback on the AsyncOperation returned from NavMeshBuilder.UpdateDataAsync to do any bake post-processing. I have a tutorial here where I show how to use NavMeshBuilder.UpdateDataAsync as well.

    While it would be preferable to have the system understand non-walkable objects include inside those objects, there are pretty straightforward workarounds for this, as well as the asset linked by Vincent that has exceptional reviews
     
    AlexTheOutsider likes this.
  37. Lord-Megabite

    Lord-Megabite

    Joined:
    Feb 21, 2015
    Posts:
    8
    Guys, use the 'Navmesh Cleaner' asset from unity asset store and problem solved. Doesnt take more than a few clicks to do it and the result is perfect. Still wondering how a company like Unity cant solve a problem on their on software like this for years, even they now that is very bad design. Navmeshes are technically 2D ? glad unity is a 3d engine XD
     
  38. Frais254

    Frais254

    Joined:
    Oct 26, 2014
    Posts:
    169
    It works really well, but with the new navmesh components it will not use links to check if an island is connected. Also if you are doing any changes to the navmesh at runtime, or have a procedurally generated world it will also cause problems as it takes quite a while to process :(
     
  39. patmckenna

    patmckenna

    Joined:
    Sep 20, 2021
    Posts:
    4
    Wow, brutal. Especially since hippocoder's workaround is the exact solution that Unity could use during baking to filter these out. CapsuleCast & reject. A trivial fix for a *checks watch* 5 year old thread. SMH
    Note: NavMeshModifierVolume isn't sufficient for my case. I want the top of my obstacle to be navigable, but not the inside.
    Guess I'll try out the Navmesh Cleaner posted above.
    Thank you to all who came before me & shared their solutions. ♥
     
    Frais254 likes this.
  40. patmckenna

    patmckenna

    Joined:
    Sep 20, 2021
    Posts:
    4
    Navmesh Cleaner is really neat but unfortunately my use-case is for baking at runtime.

    This experience has been pretty frustrating, so I'll share some of my adventure for those who come next.

    My main problem: I want the top of my obstacle(s) to be navigable, but the inside cannot be.

    Idea: split the object in two! A non-walkable object below, and a walkable object above. My objects are all box-shaped, so this was pretty easy for me. And it works!... Kind of. At least until you put two walkable objects next to each other and expect it to have a continuous navmesh.

    Apparently, the non-walkable object below messes with the algorithm such that they come out separate:
    walkable on top of non-walkable bug.png

    This behaviour is definitely a bug since it's different if the object below is marked "walkable".
    navmesh inside walkable objects.png

    And since Unity uses the Mesh Renderer instead of colliders to define the navmesh (?!?), I can't get away with just adjusting the size of the collider, I have to leave a visible ~0.2 unit gap between the two renderers for the NavMesh to be continuous.

    So, my current "solution" is going to be a 3-layer cake: a non-walkable object to cut the NavMesh on the surface below. A middle object not marked as "Navigation Static" so the NavMesh bake doesn't consider it, and finally the top most objects marked as walkable. Since the algorithm now sees a gap between the non-walkable and walkable objects, it connects the walkable ones as you would expect.

    Not a very nice workflow, but here we are. Glad I'm only working with ProBuilder cubes! Good luck to everyone else.
     
    Frais254 likes this.
  41. patmckenna

    patmckenna

    Joined:
    Sep 20, 2021
    Posts:
    4
    superdupergc and Frais254 like this.
  42. patmckenna

    patmckenna

    Joined:
    Sep 20, 2021
    Posts:
    4
    I suspect this is all because all the different
    StaticEditorFlags
    just get rolled into isStatic at runtime, so you can't have static geometry that is also not
    NavMeshStatic
    , it's all just isStatic true so it gets included in the navmesh. You either have to use layers to mark them up, or an
    NavMeshModifier
    component.
     
    Frais254 likes this.
  43. eliteforcevn

    eliteforcevn

    Joined:
    Oct 25, 2018
    Posts:
    47
    no fix today i think i should go to UE is the best choice in future :3
     
    dichtermut likes this.
  44. pumarc

    pumarc

    Joined:
    Jan 6, 2020
    Posts:
    1
    Same issue here.

    The way that old "bake" button and the new one on NavmeshSurface component is baking is not exactly the same.

    In the old "bake" buttom, it doesn't create navmesh inside an static object.
    In the new NavmeshSurface, it creates navmesh inside objects, doesn't matter if the object is static or not.
     
  45. scorp2007

    scorp2007

    Joined:
    Aug 17, 2014
    Posts:
    54
    did the solution appear?
     
  46. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,441
    yep there is an asset called navmesh cleaner. you set a few targets in your world and anything that can't reach that gets marked with a nonwalkable object that nukes them when you bake a second time
     
  47. Sacryn

    Sacryn

    Joined:
    Jan 17, 2014
    Posts:
    6
    I had the same issue. Using NavMeshSurface and NavMeshModifier(Volume) during runtime. I did my own workaround once i realized that NavMeshBuildSource has a shape property with multiple shape types. Two of which look similar but behaved different. NavMeshBuildSourceShape.Box acts as a hollow box (causing the insidedes of stuff to have NavMesh polygons). I forked the whole NavMeshComponents package and changed the modifier source to use the avMeshBuildSourceShape.ModifierBox shape instead, which acts as a solid box.

    In the end, I ended up modifing the NavMeshModifier(Volume) classes to expose a shape option, so I can properly select basics shapes or even a specific mesh to act as the modifier volume.
     
    DwinTeimlon and laurentlavigne like this.
  48. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    350
    Can you provide a link to this code? I looked on the git hub page but couldn't seem to find it.
     
  49. dichtermut

    dichtermut

    Joined:
    Jul 21, 2018
    Posts:
    26
    Is there really still no solution from Unity to this? NavMesh cleaner is not a solution for those of us who are working with runtime mesh generation.
     
  50. Sacryn

    Sacryn

    Joined:
    Jan 17, 2014
    Posts:
    6
    Epic late reply.... See attached patch file. Its probably full of bugs, but it works for my needs. We based our changes on com.unity.ai.navigation@1.0.0-exp.4 and I believe there is newer release available. So you'll probably need to tweak it a bit to fit whatever version you're using
     

    Attached Files:

    DwinTeimlon likes this.