title: In unity, baking a nav mesh at runtime for a second time causes the navmesh to only partially build
body: <p>I am currently designing a maze game in unity and have some enemy AI which chases players around the maze. If the player gets to a certain tile on the maze it'll generate a new maze with slightly larger dimensions.</p>
  <p>I've been using the unity AI NavMeshSurface class to achieve this and calling <code>surface.BuildNavMesh()</code> to generate the nav mesh once the level has been generated.</p>
  <p>The current level's maze game object(s) get destroyed each time the level is regenerated:</p>
  <pre>
  
      public void GenerateNewMaze(int rows, int columns)
      {
          mazeData = dataGenerator.FromDimensions(rows, columns);
          DisplayMaze();
      
          surface.BuildNavMesh();
      }
      
      public void DisposeOldMaze()
      {
          GameObject[] mazeObjects = GameObject.FindGameObjectsWithTag("Generated");
      
          foreach (GameObject mazeObject in mazeObjects)
          {
              Destroy(mazeObject);
          }
      }
  
  </pre>
  <p>The first time I run this it works perfectly:</p>
  <p><a href="https://i.stack.imgur.com/gsqBY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gsqBY.png" alt="First generation" /></a></p>
  <p>However from the second onwards I start getting some strange gaps:</p>
  <p><a href="https://i.stack.imgur.com/i4CjM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i4CjM.png" alt="enter image description here" /></a></p>
  <p>I thought maybe the surface somehow still had the old data after doing some googling and I tried a couple of solutions such as <code>surface.RemoveData()</code> and <code>NavMesh.RemoveAllNavMeshData()</code> before building the navmesh again but I seem to get the exact same results.</p>
  <p>Currently I can only think to create a new NavMeshSurface per maze generation but that seems overkill and unnecessary.</p>
  <p>The tutorial I followed to do this was: <a href="https://www.youtube.com/watch?v=FkLJ45Pt-mY" rel="nofollow noreferrer">https://www.youtube.com/watch?v=FkLJ45Pt-mY</a></p>