Best way to update grid graph when adding several colliders

I have some objects the player can place in my game during runtime, some of these objects contain several box-colliders (as children) AKA compound collider.

Currently, when I scan manually it scans perfectly, but when I scan using the code below, only part of the colliders are registered as obstacles. Not sure if this code is supposed to handle compound colliders or if there is some way to pass a list of colliders.
If not, what would be the most performant way to update when adding several colliders? Feels wasteful to update entire graph when I know exactly what Im adding.

var guo = new GraphUpdateObject(collider.bounds);
guo.updatePhysics = true;
AstarPath.active.UpdateGraphs(guo);

Hi

collider.bounds is just the bounding box of a single collider. You will need to calculate the bounding box of all colliders for this to work as expected.

You can use Bounds.Encapsulate to do this (see unity docs).

1 Like

Iā€™ve noticed that in a Grid graph, even if I am using GraphUpdateObject(collider.bounds), it will update other nodes on the grid that are not within those bounds.

For example, I place 20 buildings, while these are being constructed I do not want them to act as obstacles, so I call GraphUpdateObject(collider.bounds) once construction is finished. However this seems to update adjacent nodes too, setting some uncosntructed building-nodes to unwalkable.

Is this intended?

An update within a region is treated as ā€œassume something changed inside this bounding box, update all nodes that could possibly be affected by thatā€. Since for example the ā€˜collision testingā€™ options make each node check for obstacles within a volume around itself we have to expand the bounding box by a small amount to account for that. Erosion also causes the bounding box to have to be expanded.
The goal is that it should yield the same result as if the graph was scanned from scratch (assuming you call UpdateGraphs with all regions where things have changed).

1 Like

Cool, then I know! I can simply toggle the collider isTrigger to make sure it does not get registered as an obstacle before I want it to.

1 Like