Hi, I’m trying to update the walkability of a complex (non-convex) area on a grid graph. The approach I’ve taken is to have a polygon collider to specify the the area that needs to be updated. I convert the colliders points from Vector2 to Vector3 by setting their z value to 0 (the grid graph position is at z=0) and then use these points to create a GraphUpdateShape. Here is the code:
Transform cachedTransform = transform;
Vector3 localPoint;
// Get the points from the collider and convert them to 3d
Vector3 points = new Vector3[_areaCollider.points.Length];
for (int i = 0; i < _areaCollider.points.Length; i++)
{
localPoint = new Vector3(_areaCollider.points[i].x, _areaCollider.points[i].y, 0);
// Convert the point from local space to world space and add to the array
points[i] = cachedTransform.TransformPoint(localPoint);
}
// Define a graph update shape based off the collider 3d points
GraphUpdateShape shape = new GraphUpdateShape();
shape.convex = false;
shape.points = points;
// Create a Graph update Object based on the GraphUpdateShape and modify the tag for the nodes
// within the shape
_updateObject = new GraphUpdateObject();
_updateObject.shape = shape;
_updateObject.trackChangedNodes = true;
_updateObject.modifyWalkability = true;
_updateObject.setWalkability = false;
// Apply the graph update
AstarPath.active.UpdateGraphs(_updateObject, 0);
It never detects any nodes within the shape. If I set the GraphUpdateObject to use the bounds of the collider, it works (but not as accurate of course). I have even tested using the bounds of the shape (which is exactly the same as the bounds of polygon collider) and not the shape itself, it still does not detect any nodes. It only seems to work if I do not use GraphUpdateShape at all.
Any suggestions or ideas as to what is going on?