# NavMesh.CalculatePath returns invalid path Unity3D

I am trying to get coordinates for path from source to destination object using NavMesh. NavMesh.CalculatePath() is only working for one level surprisingly. For all others, it returns false. Also NavMeshPathStatus is invalid. This is working Level, while this is not working fine with navmesh.

Code:

private NavMeshPath path;

void Start () {
path = new NavMeshPath();
}

//Following function is called on button press
public void giveHint() {

NavMesh.CalculatePath(source.transform.position, destination.transform.position, NavMesh.AllAreas, path);

if (path.status == NavMeshPathStatus.PathComplete)
print ("Path complete");
else if (path.status == NavMeshPathStatus.PathInvalid)
print ("Path invalid");
else if (path.status == NavMeshPathStatus.PathPartial)
print ("Path partial");

for (int i = 0; i < path.corners.Length-1; i++) {
Debug.Log(path.corners[i]);
}
}

// Update is called once per frame
void Update () {
if (path.corners != null) {
if(path.corners.Length > 0) {
for (int i = 0; i < path.corners.Length-1; i++) {
Debug.DrawLine (path.corners [i], path.corners [i + 1], Color.red);
}
}
}

}


Please tell me way to debug/solve this issue. How unity calculates path between source and destination? Can there be possibly blockage in path? If yes then how? How path is invalid? Is there any bottleneck with the usage of CalculatePath function? Need guide from you guys... Thanks!

• Check what CalculatePath is returning. If it's false, then it was unable to find a path. – Foggzie Aug 8 '16 at 20:37
• could you somehow display your navmesh? the one working and one which isn't? Or check the way you initialize the navmesh in other levels – Leggy7 Aug 8 '16 at 20:39
• @GuntherFox It is returning false. Just checked :( – NightFury Aug 8 '16 at 20:41
• I never used navmeshes but I assume that you somehow set up in the scene view and have properties in the inspector. maybe a print screen of that and also of the shape in the scene view could be of help – Leggy7 Aug 8 '16 at 20:44
• @Lara If it's returning false then my guess is there is some obstacle or obstruction. – Foggzie Aug 8 '16 at 20:45

Finally, I figured out where I was wrong. I have a cube gameobject as destination. I was not making it part of navmesh baking. Navigation Static was not marked for it. So when navmesh was baked, destination was not included as part of it, so path status was invalid.
I cleared the navmesh, made my cube Navigation Static and Walkable, baked the navmesh again. Now I am getting valid path for all my levels.