Home > Net >  Unity Navmesh bake multiple maps in the same scene
Unity Navmesh bake multiple maps in the same scene

Time:06-05

I have an scene with multiple maps, and when the game starts I randomly activate one of the maps and keep the others inactive.

My problem is that I can only have one the maps baked, because when I change to bake other map it's overwrited by the previous bake.

I search for other post to try baking at runtime but is seems it's not possible.

Is there a way to have multiple bakes or to bake only the active map at runtime?

CodePudding user response:

To solve the problem, you can call the bake navigation code after the level changes.


Bake Navigation Inside Unity Editor

This code works similar to what is in the Unity Editor. Just make sure your Navigation Static object is enabled before using it.

enter image description here

The NavMeshBuilder class will allow this. In the code bellow.

using UnityEditor.AI;

...

public void Generate()
{
    GenerateLevel(); // for e.g

    NavMeshBuilder.BuildNavMesh();
}

Bake Navigation in Runtime

To bake in runtime, you need to download the necessary enter image description here

public List<NavMeshSurface> surfaces;

public void Start()
{
    GenerateLevel(); // for e.g
    
    surfaces.ForEach(s => s.BuildNavMesh());
}

Also this tutorial from Brackeys will help you so much.

  • Related