When baking a Navmesh Surface at runtime 'Include Layers' property gets ignored

I am using the Unity NavMesh Components to bake a randomly generated map in my game.

I use the NavMesh Surface component to be able to bake during runtime. I have my player gameObject standing on top of the map ant to make it so that the area around it does not get cut out I set the player (and all it’s child objects) on a separate layer called “Player”. Then I set the Surface ‘Include Layer’ property to every layer except the “Player” one. When I bake in the scene (not during runtime) the player gets ignored and the map around it is set as walkable (highlighted in blue).

The problem is that without changing anything (no parameters, no layers, no properties…) when I bake during runtime the player is counted as an obstacle and the map around him is cut out of the NavMesh.


I bake the surface at runtime like this:

 using UnityEngine;
 using UnityEngine.AI;
 
 public class NavigationManager : MonoBehaviour
 {
     public NavMeshSurface surface;
 
     public void Bake()
     {
             surface.BuildNavMesh();
     }
 }

I think I could “fix” this issue by moving the player up in the sky before baking and then bringing it back to its position, but this is just a work around. Am I doing something wrong, or is it a bug of the NavMesh Components?

Any luck here? I’m having the same issue.

First of all please check if these are set correctly:

  1. Navmesh agent component collider is placed correctly on player model.
  2. Be sure you applied the Navmesh included layers on the level gameobject.
  3. Check for any ignore from build Navmesh modifier component on any of the level gameobjects.
  4. Be sure that the Navmesh is set to calculate Mesh instead of physical collider incase u didn’t add colliders to the map
  5. Try to manually bake your Navmesh on runtime to find the issue.

Lastly provide screenshots for your Navmesh components in case this didn’t help.