Hi, I’m currently working on a scene where I create a new maze-like level each round, with randomly generated walls, and enemies spawn around the edges of the level and move toward the center. In order to make the enemies path properly, they each have a Nav Mesh Agent and the wall prefabs have Nav Mesh Surfaces. Currently, I call NavMeshBuilder.BuildNavMesh(); after putting in the new walls, and this causes the enemies to properly pathfind around them. There’s only one problem: rebuilding the nav mesh like this causes the game to freeze for several seconds when it’s called.
How can I generate new terrain like this so that the enemies will path around it properly without freezing? Can I rebake the mesh asynchronously? One thing I tried was giving the wall prefabs Nav Mesh Obstacles, which removed the need to rebake the mesh, and the enemies do avoid the walls, but the enemies no longer take the most efficient route to the goal and tend to wander a bit. What’s the best solution here? Thanks