I am currently checking if a position in the NavMesh is reachable. It is reachable without the NavMesh obstacles. But the moment I add it, NavMesh's CalculatePath() continues to return true. Note that I do have those obstacles to have carving set to true. How do I solve this problem?

Reference: https://answers.unity.com/questions/1184356/how-to-know-if-a-navigationmeshagent-is-impossible.html


I fixed my problem by doing the ff:

public bool CanReachPosition(Vector2 position)
      NavMeshPath path = new NavMeshPath();
      agent.CalculatePath(position, path);
      return path.status == NavMeshPathStatus.PathComplete;

After getting the path, we need to check if the path is NavMeshPathStatus.PathComplete or if the path is getting to the destination. The path will be .PathPartial if the path is incomplete.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.