hasPath Issue during path recalculation

  • A* version: 5.3.3
  • Unity version: 6000.0.34f1

Hi, I’m using FollowerEntity. While performing pathfinding, there is an issue where hasPath momentarily (for 1 frame) switches to false and then returns to true. (but the pathPending value remains false) It seems like this happens during auto recalculating by NavMeshCut.

so, it causes issues with checks like hasPath && !reachedEndOfPath. Is there an alternative checking method to bypass this issue? Thanks

Hi

This is expected. When a navmesh cut happens, it can make the agent’s path invalid. It will immediately try to recalculate the path and in your case it seems to do so very quickly. Most likely pathPending returns true for only a very short while, and your code doesn’t notice. The agent only checks for if the path needs to be recalculated once per frame, which is why hasPath and pathPending can both be false.

Thank you for the explanation.
I found that the pattern ‘hasPath && !reachedEndOfPath’ appears in many examples.
Is there a more reliable way to determine whether the agent is currently moving toward its target?

Hi

That pattern is primarily useful with AIPath/RichAI/AILerp. The FollowerEntity has much stricter guarantees on its properties, and you should be able to use just !reachedEndOfPath for most purposes.