Hi,
I am trying to calculate a path, and then the length of this path between two arbitrary positions on a NavMesh. The function NavMesh.CalculatePath always claims to have found a path by returning true, but the path has 0 corners, and thus 0 length. Has anybody encountered this behaviour/Is this expected behaviour? I have tried this in a minimal test environment with the same results. I will attach a script to demonstrate.
I’d also like to mention the issue doesn’t seem to be the NavMesh setup, an agent placed in the world behaves exactly as expected.
Thanks for any help
public class test : MonoBehaviour
{
public GameObject obj1;
public GameObject obj2;
// Update is called once per frame
void Update()
{
NavMeshPath path = new NavMeshPath();
bool worked = NavMesh.CalculatePath(obj1.transform.position, obj2.transform.position, NavMesh.AllAreas, path);
Debug.Log(worked);
float pathLength = 0;
for ( int i = 0; i < path.corners.Length - 1; i++)
{
pathLength += Vector3.Distance(path.corners*, path.corners[i+1]);*
}
Debug.Log(pathLength); //path.corners.Length always = 0, and of course pathLength always = 0
}
}