- Home /
Why does the NavMeshPath.corners only contain 1 waypoint?
Hello.
Im trying to get the path that my NavMeshAgent is following, and I read in the script reference that NavMeshAgent.Path is what I want.
I read on, and saw that the Path is stored as Vector3 array, in NavMeshPath.corners.
However, as I tried to spawn spheres at all the vector3's in the array, to my amazement it only spawned 1 or 2.
I want the full path, so I can show my player the route of the player character before he starts moving, but I can only ever get 1-5 waypoints, although sometimes it give me up to 20 waypoints from the NavMeshPath.corners array. The only waypoint is the actual destination, and not the full path, even though my agent navigates perfectly through a whole maze.
What is going on here? I might have misunderstood something, or maybe the unity pathfinding is simply so brilliant it only needs 1 waypoint?
Anyway, some info on this, or perhaps another way of doing it?
Here is the function for good measure.
void DrawPath(NavMeshPath path)
{
Debug.Log(path.corners.Length);
foreach (Vector3 point in path.corners)
{
Instantiate(waypoint, point, Quaternion.identity);
}
}
Hi, could you provide the code that is spawning the spheres from the Nav$$anonymous$$esh array info, thanks :)
Have you put a Debug line inside the loop to check that it is run the same amount of times as the Length that you print above?
Yes, and it loops the same amount of times. I do seem to get more waypoints sometimes, and other times it only gives me 1? It's kind of random. I use mouse click to place the player destination, and when I click once, at the end of the maze, i only see 1 waypoint, and that is the first one. If I Spam random locations for him to walk, I sometimes get more, but not the whole route.
Your answer