I have a small test scene with simple areas that aren’t connected. I have a NavMesh baked. I’ve got a character with a NavMeshAgent and I’m placing a target at random points within 10 units of the character, then using NavMesh.SamplePosition. If it passes that, I use SetDestination on the agent, then check pathStatus for PathComplete or PathPartial (I’m using PlayMaker, but these are the methods being used by the actions).
The problem is that when the random target is placed on another area that’s not connected to the area the agent is on (and even if there is a wall completely blocking the area), pathStatus is returning PathComplete, and the agent gets stuck trying to get to an unreachable area.
From what I’ve read, using SetDestination causes the path to be calculated in a separate thread, so it’s not available immediately. The PlayMaker action I’m using fires events (Path Complete Event, Path Partial Event) so I would think that would work. It waits for one of these events and then either moves towards the target or generates a new target if it can’t be reached. It works fine if the target is on the same connected area, but breaks when on an unconnected area.
Anyone know why it would return pathComplete when it’s not possible for the agent to reach the destination?
Edit: I forget to add that I had also tried it with NavMesh.CalculatePath, then using Agent.SetPath and checking path status and that does seem to work. But I would like to get it working with SetDestination as above.
If I remember correctly the NavMeshAgent will, when given a target it cannot reach, actually set its destination to the furthest point on the path it can reach and use that as destination. Because of that you always get the Complete result.
You can debug this perhaps by spawning a little cube on the Agent’s destination after you’ve set it?
Ok, I added a cube and I place it at the current agent destination after checking path status. It’s the same as the target destination, so I really don’t understand what’s going on here.
I think I have it working now. The ‘Get Agent Path Status’ action wasn’t waiting for pathPending == false (I assumed it was). I added a state that runs until pathPending becomes false before it tries to check Path Status.
While trying to solve this I found a good article that shows how the nav mesh system behaves in various situations that isn’t always obvious. It might be helpful to others with similar problems.
Taming Unity’s Navigation System - Assumption Testing Part 1
2 Likes
This hasn’t helped me, I’ve still been 38m away from a destination and pathPending=false and pathStatus=PathComplete.
It looks like I’ll have to go back to checking just distance to target again with some sort of other additional AI
I used NavMeshAgent on a large project 2 years ago and it was a mess for this sort of thing, it seems it’s no better in 2020.2
It’s still a complete mess year of our lord and savior 2022
is there an alternate way to check if the target is reachable? this method is broken. Shame on Unity for not improving their core engine features that thousands of devs rely on
1 Like
Thanks you so much you saved me a lot of time and effort 