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?