Search Unity

Question NaveMeshSurface.BuildNavMesh() produces bad results

Discussion in 'Navigation' started by OctoSharko, Jan 9, 2024.

  1. OctoSharko

    OctoSharko

    Joined:
    Dec 9, 2016
    Posts:
    35
    Hi,

    I am using the AI.Navigation system on the following scene :
    Screenshot 2024-01-09 at 14.58.05.png


    Since it's a scene with element which will be deleted dynamically, I'm not baking the scene beforehand but call once
    Floor.GetComponent<NavMeshSurface>().BuildNavMesh();

    "Floor", beeing the game object holding the NavMeshSuface component.
    The first call does a pretty good job (Except for some reason it exclude the player with the NavMeshAgent, although the player also has a NavMeshModifier component with remove, why ?).
    Screenshot 2024-01-09 at 14.58.20.png

    Then the next time Floor.GetComponent<NavMeshSurface>().BuildNavMesh(); gets called, is when the the game object on the left (the dumpster/garbage) is set to inactive. And then the results is completly wrong :
    Screenshot 2024-01-09 at 14.58.55.png

    What am I not understanding, doing wrong ? I would like to be able to create a dynamic mesh at runtime which will adapt to active/inactive objects preset with NavMeshModifiers (add/remove). For example, if the dumpster blocks a path, setting it to inactive should "open the path".

    I've followed all tutorials I could find, but still can't understand what I am doing wrong.

    Thanks
     
  2. OctoSharko

    OctoSharko

    Joined:
    Dec 9, 2016
    Posts:
    35
    Ok fixed it buy using NavMeshObstacle and NavMeshModifier components properly