Hello Unity community! I'm trying to sample path position from a running navmesh agent, but it constantly fails. Code (CSharp): var sampled = agent.SamplePathPosition(NavMesh.AllAreas, 0, out sample); The sampled flag is always false and the sample.hit flag is always false and sample.mask equals 1, wich means Unwalkable area. I've logged the agent's state at the moment of sampling, here's the output. Here you can clearly see the agent moving over Walkable area (mask 0) painted with blue. How do I get the area mask at the current agent's position?
Looks like the result is correct: The returned mask matches the default walkable area type namely 1<<0 . The return value is false because the position along the path is 0 distance ahead - and not blocked. See also: https://docs.unity3d.com/ScriptReference/AI.NavMeshAgent.SamplePathPosition.html
The hit bool refers to whether the position is blocked (areaMask) while scanning the path some distance ahead. See also the example code in the documentation
Oh, I see. To make things clear. When using NavMeshAgent.SamplePathPosition, the resulting sample .hit flag shows if the position was blocked or sampled at distance requested. And when using NavMesh.SamplePosition, the resulting sample .hit flag shows if position on the navmesh found or not. This isn't stated in the docs here https://docs.unity3d.com/ScriptReference/AI.NavMeshHit.html, may be it should? Anyway, thank you for clarification