Search Unity

Resolved Only add Children as navmesh source, but let anything else be a blocker

Discussion in 'Navigation' started by Guedez, Sep 1, 2021.

  1. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    So I've split my map into many navmeshes, and started using the map mesh to generate the navmeshes, because volume + blockers is just WAY too much work, especially since the blockers will interfere with adjacent meshes. So I want to know, how to specifically create a navmesh through a mesh, but let anything in the scene to be a blocker?
    upload_2021-9-1_17-30-50.png
    Those fences for instance, are not blocking the navmesh as they used to since they are not children of the region they are standing on. For the fences in specific I could solve it by exactly doing that, moving them to be a child of the navmesh, but it's not something I can do to every single other object in the game.
     
  2. darkwingfart

    darkwingfart

    Joined:
    Oct 13, 2018
    Posts:
    78
    Attach a NavMeshObstacle to the fences and set them to carve.
     
    Guedez likes this.
  3. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    I plan on eventually making those fences entities, or simply draw them with DrawMeshInstanced, so although that worked perfectly fine right now, I don't plan on having them being GameObjects forever.
     
  4. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    Change the code of NavMeshSurface. Just click on the three dots on the top right corner of a NavMeshSurface and then on "Edit Script" - there you will find the method that collects objects. Tell it that it collects ALL scene objects and put the "non walkable" mark on everything that's not a child.
    Make sure the method is performant, if you don't want to wait 10min every time you click "bake" (use HashSets) ^^

    I changed the code, so it ignores tirggers, but you can do anything you want with it.
     
    Guedez likes this.
  5. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    My experience with checking the source of the AI package has been that 99% of methods are just [extern] dll calls... good to know NavMeshSurface is editable. TIme to get my hands dirty.
     
  6. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    Somehow couldn't get 'external sources' to get modifiers applied to them, but I've managed to add other meshes as obstacles, nice tip.