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

Clear NavMeshSurface

Discussion in 'Navigation' started by lofwyre, Feb 13, 2018.

  1. lofwyre

    lofwyre

    Joined:
    Apr 19, 2007
    Posts:
    166
    How do you clear a NavMeshSurface?

    I have tried

    Code (CSharp):
    1. NavMeshData.Destroy(CurrentFloorInstance.GetComponent<NavMeshSurface>().navMeshData);
    and

    Code (CSharp):
    1. CurrentFloorInstance.GetComponent<NavMeshSurface>().navMeshData = new NavMeshData();
    and

    Code (CSharp):
    1. CurrentFloorInstance.GetComponent<NavMeshSurface>().RemoveData();
    I'm using GetComponent<NavMeshSurface>().BuildNavMesh() on load of a level to build it. But on each level load the nav mesh data from the previous level still seems to be there as well.

    Additionaly I'm destroying the gameObject the navmesh component is on at the start of the level. But it seems when I instantiate it again, the old navmesh data is still hanging around.

    Cheers
    Matt
     
    DashW likes this.
  2. famishedgibbon

    famishedgibbon

    Joined:
    Jun 14, 2018
    Posts:
    1
    Did u ever solve this? I am having the same issue.
     
  3. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    705
    Code (CSharp):
    1. NavMesh.RemoveAllNavMeshData();
    or
    Code (CSharp):
    1. NavMesh.RemoveNavMeshData(YourNavMesh);
    This works for me
     
    egesefer and muhammad_ali_safdar like this.
  4. Mohido

    Mohido

    Joined:
    Feb 21, 2021
    Posts:
    1
    I had the same problem, However I solved it with this idea: You can move the first scene so it does not overlapped with the new baked navmesh.
    Note: Make sure to delete the old navmesh.asset
     
  5. muhammad_ali_safdar

    muhammad_ali_safdar

    Joined:
    Jan 7, 2015
    Posts:
    15
    1. NavMesh.RemoveAllNavMeshData(); // its Work