- A* version: [5.3.3] (purchased version of A* Pathfinding Project Pro)
- Unity version: [6000.0.32f1]
Hi, I’m currently adapting my code to more closely consider the GraphNode Area property, because I wasn’t doing so previously and was getting issues using functions like GetNearest, RandomPointOnSurface, PathUtilities.IsPathPossible etc.
I think if you have a graph that only uses a single area, you naturally won’t encounter problems. However, when a new area is introduced (say if one graph has a gap that cuts it in two) then setting the NNConstraint Area becomes essential.
One thing I’m not clear on though, is when these areas of a graph change.
I am seeing areas of the same graph switch. Is this behaviour supposed to be predictable, or should we accept that Areas change periodically/randomly?
For example, I have one small example scene with one Recast graph, divided into two Areas, and an object with a Navmesh cut component.
On scene loading, the Area on the right with the Navmesh cut is 2 (green color):
If I move the object a bit more to the left, without leaving the grid surface, the same Area suddenly becomes 1 (purple color):
Is this valid/expected behaviour?
Good question
I’ll have to defer this one as well to @aron_granberg as I’m not entirely sure myself- curious now too.
With that in mind, what issues were you running into?
Only that I needed to consider the Areas when using those functions - I was initially naively just passing NNConstraint.Walkable in as my constraint. For example, now I know when looking for a random point which is reachable I make sure its in the same area:
public Vector3 GetRandomDestinationInArea(Vector3 start)
{
// Find a valid starting node
NNInfo nninfo1 = AstarPath.active.GetNearest(start, walkableConstraint);
if (nninfo1.node == null)
{
Debug.LogError($"GetNearest start {start} could not be found!");
return start;
}
areaConstraint.constrainArea = true;
areaConstraint.area = (int)nninfo1.node.Area; // make sure area matches
NNInfo sample = AstarPath.active.graphs[0].RandomPointOnSurface(areaConstraint);
if (sample.node == null)
{
Debug.LogError($"RandomPointOnSurface from start {start} could not be found!");
return start;
}
return sample.position;
}
My concern though with the Areas swapping around like in my example in the fist post is that an area that was initially a valid destination will now be a different area - so holding on to an area and keeping groups of agents in-synch gets a bit tricky.
Areas can change whenever the graph is updated. The values are arbitrary, so you should not rely on them staying the same unless you can guarantee that you aren’t doing any graph updates.
Instead, you can keep track of references to nodes that you know are one group or another, and read its area property at the relevant time.
1 Like
Yup fair enough, just wanted to confirm. Thanks