What would cause result from Calculate Path to differ from SetDestination
My AI use NavMeshAgent.CalcuatePath. However, I have a reproducible case where the method returns an invalid path (returning false), despite no obvious reason - i.e. looking at the NavMesh a simple valid path was available.
If I use NavMeshAgent.SetDestination in the same place, a valid path is found. Specifically:
NavPath = new NavMeshPath();
bool result = agent.CalculatePath(destination, NavPath);
bool result2 = agent.SetDestination(destination);
Reliably at one point, when the code runs, result = true but result2 = false. (In the same FixedUpate frame) What could cause this? Does CalculatePath have different constraints or assumptions, or is it a bug in Unity?
Answer by Silverlode · May 19, 2017 at 01:04 AM
Well.... I have solved my problem... ...but it doesn't quite explain the discrepancy here.
Both CalculatePath and SetDestination were in fact failing to create a complete path.
CalculatePath returned a path with 0 corners, status invalid, method result false.
SetDestination returned a path with 1 corner (the starting position!), status complete (wrong!) and method result true (also misleading).
The reason I was failing to get a (genuinely) complete path is my destination was below the surface of the navmesh! Ooops.
It seems that the paths / logic resulting from SetDestination and CalculatePath aren't identical - although the difference, in my case, was ultimately of practical significance.
Your answer
Follow this Question
Related Questions
Farthest Reachable Destination 0 Answers
How to exclude certain navmesh obstacles on runtime? 2 Answers
Nav Mesh Agent can't decide on path 0 Answers