- Home /
Trouble with NavMesh.CalculatePath
I'm working on a game that uses grid based movement.
I'm using Unity's built in pathfinding to determine my paths, then using the resulting path to determine where to move my enemies.
I'm simply using some permutation of
NavMesh.CalculatePath(transform.position, patrolPoints[currentPatrolPoint],
NavMesh.AllAreas, path);
without a NavMeshAgent attached to my enemies
However, it's become apparent that CalculatePath doesn't seem to work immediately, and that it may take a few frames for the path to be calculated at all.
This is a problem, since I am using the validity of the path as a determining factor in my enemies' AI, as to whether or not they should move, and I'm calculating the path and then immediately checking some conditions on said path.
My current plan is to wrap CalculatePath in a coroutine that first checks its validity before allowing the enemy to continue its own execution, but this seems like a clunky and imperfect solution, especially given that there is no way to tell (as far as I can find) whether or not the path has finished calculating.
The closest thing I can see in that regard is NavMeshPath.status--but that only holds information about the actual path itself (Partial, Complete, Invalid)--not about the status of the calculation being completed.
Any ideas?
Thanks!
Answer by jakejolli · Aug 01, 2017 at 01:24 PM
So, after more investigation, it appears that it wasn't a delay in the path being calculated, but the fact that my enemy had an attached NavMeshObstacle attached, which was preventing the path from being appropriately calculated.
Your answer
![](https://koobas.hobune.stream/wayback/20220612131654im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
check if an object is reachable 2 Answers
Is it possible to translate a NavMesh at runtime? 2 Answers
walking through the countryside ? 1 Answer
Navmesh with destructible obstacles 1 Answer