Path.Status says complete but it's obviously not

if (NavMesh.CalculatePath(transform.position, searchPosition, NavigationQueryFilter, path)
        && path.status == NavMeshPathStatus.PathComplete
        && path.IsPathWithinCost( MovementDistanceCost, NavigationQueryFilter))
               {

The IsPathWithinCost function calculates the Cost of a path by comparing Areas Costs and distances traveled within them and compares it to a max cost to return a bool. It’s not the problem though; path.status == NavMeshPathStatus.PathComplete is coming out true and from the picture below, it’s obviously not true.

The blue cube is the location I’m searching for
The magenta line is the Path that’s returned
The white sphere is the last point in the Path. (which matches up correctly with the edge of the Unit’s NavMesh)

Location it was searching for (212.5, 0.5, 223.7)
Location of the last path.corner (215.7, 0.2, 223.1)

I thought that NavMesh.SamplePosition might catch that this point is off my NavMeshes (I currently have 3), but it too seems to think that this position is totally valid.

if (NavMesh.SamplePosition(indexPosition, out hit, 5f, NavigationQueryFilter)
        && NavMesh.CalculatePath(transform.position, indexPosition, NavigationQueryFilter, path)
       && path.status == NavMeshPathStatus.PathComplete
       && path.IsPathWithinCost( ThisUnitCommand.MovementDistanceCost, NavigationQueryFilter))
                {

Found a solution

NavMesh.SamplePosition(indexPosition, outhit, 1f, NavigationQueryFilter)

Tuning the search radius down to 1meter has resulted in reasonable results.

Still confused as to why the CalculatePath is so certain that it has a completed path…

1 Like

Thank you