Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to get navmeshagent to ignore trees on terrain

Discussion in 'Navigation' started by Ben_Iyan, May 20, 2018.

  1. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    203
    There are quite a few posts about this subject and the only workaround that seems to work is to delete all of the trees, bake the navmesh, and then use UnDo to put the trees back. This would be a great deal of work for my terrain, and if I adjust the terrain, I have to do it all over again. Has anyone found a more elegant fix for this?
     
  2. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    I'm sure there is a more elegant solution. Several options come to mind:
    Make your tree prefabs non-static. The navmesh will ignore anything not static, you could also remove collider or the navmeshobstacle.
     
    Ben_Iyan likes this.
  3. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    203
    @newjerseyrunner Thanks for the tips! I have a number of different tree types, so I'm not keen on removing the colliders on all of them. My workaround, for now, is to use the new (beta) Navmesh Surface because (at least for now) it ignores trees. Hopefully when Unity implements that part, they'll provide a toggle like the useless one that is currently part of the Navmesh. Thanks again for taking the time to help.:)
     
  4. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
  5. MaximumTre

    MaximumTre

    Joined:
    Nov 28, 2015
    Posts:
    163
    Have you tried adding a nav mesh obstacle to the tree prefabs?
     
  6. im47

    im47

    Joined:
    Oct 17, 2022
    Posts:
    1
    Sorry for joining this discussion late, but I encounter the same problem and found a solution. I want to use grass and tree prefabs, but I want the Nav Mesh to ignore the grass, and only include the tree. I'm populating the grass and trees using the "Paint Trees" in the Terrain component, and whenever I want to add Trees (Paint Trees>Edit Trees) there is an option for Nav Mesh LOD Index. So, if the prefabs you want to add as tree has LOD, you can choose which LOD Index to be calculated in the Nav Mesh. And so, I make a fake LOD level for the grass, and basically assigning nothing on that LOD level. And if I choose this LOD level for the Nav Mesh, the grass will be treated ass nothing, and will be ignored in the Nav Mesh.

    Tested on Unity 2021.3.25f1
    Hope this help.

    upload_2023-5-28_14-17-35.png
    upload_2023-5-28_14-16-40.png

    upload_2023-5-28_14-19-34.png