NavMesh.CalculatePath not genereating path from NavMeshSurface
Hello,
I'm having an issue with calculating paths. First off, yes my public fields have the correct variables assigned in the inspector.
If I bake my nav mesh from within the NavMeshSurface component that has been applied to my gameObject, the navmesh generates just fine using the agentID I intend. You can see the blue area applied nicely exactly how it is supposed to. If I run the code below, the path.corners.length will be 0 (No path).
NOW, if I open unity Navigation menu, click on the Bake tab, and bake the same agentID I used before, I will also see a second newly generated navigation mesh nicely laid out over my scene. Now, if I do not change a thing about my code and run the scene, the path.corners.length will now be filled with waypoints as expect. The problem with this is it negates the point of using NavMeshSurfaces all together. The point of which being that I can bake multiple agentID's for use in my scene. If I can not calculate paths on NavMeshSurfaces I'm afraid it's pointless to use surfaces.
My fear is that NavMesh.CalculatePath(); does not work with navMeshSurfaces. Can anyone confirm? Or tell me what it is I'm doing wrong?
public Transform target;
public NavMeshPath path;
public NavMeshSurface navMeshSurface;
private NavMeshQueryFilter navMeshQueryFilter = new NavMeshQueryFilter();
private float elapsed = 0.0f;
void Start()
{
path = new NavMeshPath();
elapsed = 0.0f;
navMeshQueryFilter.agentTypeID = navMeshSurface.agentTypeID;
navMeshQueryFilter.areaMask = navMeshSurface.layerMask;
}
void Update()
{
elapsed += Time.deltaTime;
if (elapsed > 1.0f)
{
elapsed -= 1.0f;
NavMesh.CalculatePath(transform.position, target.position, navMeshQueryFilter, path);
}
for (int i = 0; i < path.corners.Length - 1; i++)
Debug.DrawLine(path.corners[i], path.corners[i + 1], Color.red);