CalculatePath always Invalid [SOLVED]

I’m getting back into Nav Meshes again :slight_smile:

but my CalculatePath call is always invalid… UNLESS… I set the origin and target to sampled positions on the nav mesh.

Do I really need to sample NavMesh positions everytime I want to calculate a path?

Shouldn’t the CalculatePath call do this automatically?
I have 2 positions, they may/may not be exactly on the nav mesh surface. Some points might be offset. Seems very strange to me that I have to change the positions to match a point exactly on the surface to get a valid result.

CalculatePath does try to map the positions to the NavMesh, but the search distance depends on the radius and height of the agent type you specify, otherwise it falls back to the radius and height of the default agent, which usually is 0.5 horizontally and 2.0 vertically. World positions that are further away from the NavMesh than these values will not be mapped.
Does it work for you when the positions you pass to CalculatePath are within these ranges relative to the NavMesh?

2 Likes

Ah I see, yeah I had to change my agent height to a large value. I’m building a game with water waves, the waves offset the positions so yeah, making the height large enough does the job.

Thanks

I’ve encountered same problem with NavMesh.CalculatePath();
Path is always returns as PathInvalid if the height is set lower than 1.5. Can’t figure out why it’s happening.
I’m doing it like so. I doubt it can’t find the start position, hence it doesn’t print out the error. This feels like a bug.

NavMeshHit hit;
if (NavMesh.SamplePosition(samplePosition, out hit, 1000, NavMesh.AllAreas)) {
    if (!NavMesh.CalculatePath(hit.position, destination, NavMesh.AllAreas, _path)) {
        Debug.Log(_path.status);
    }

    ProcessPath();
 } else {
       Debug.LogError(this.ComponentName() + "Entity is too far from the nav mesh");
}

Actually, nvm. It does work with 1.2 height, but anything lower is just causing PathInvalid.

I have the same problem , but my agent radius is 8, height is 20.

Any idea?

Happens the same, always invalid path, i check it at start and gives invalid path, i changed height but doesnt matter, i have no way to know if path is invalid, agent.destination gives a path as models move but the path is always invalid

Thanks, Changing the height of the agent from AI-Navigation window worked for me.