Updating a Grid Graph after removing an object

Hi!

I am having problems with updating my Grid Graph after I remove an object( it’s stationary) from the scene. When I Initialize the object I use the code below.

AstarPath.active.UpdateGraphs(collider.bounds);

This works exactly as I want. My problem comes when I want to remove the object.
image of the problem

I use this code for removal/restoration of the grid.
GraphUpdateObject ob = new GraphUpdateObject(collider.bounds); ob.modifyWalkability = true; // Do modify walkability ob.setWalkability = true; // Set walkable to false AstarPath.active.UpdateGraphs (ob);

I would like it to go back to it’s “normal” state, as everyting around it.
Right now when I remove the larger green square I get an empty area and a floating grid square. When I remove the smaller purple square I get a small empty area and the marker stays.

If I press “Scan” on the Grid Graph everything goes back to as I want it but Scan is supposed to be costly soo I would like to update the graph without using it if possible.

Thanks in advance,
Towni0

EDIT: Ignore the small purple square in the bottom center of the image.

Hi

The reason is that even though you are setting all nodes to be walkable, they are still in the wrong position.
My suggestion is to disable the collider and use the same code as you did at the start, that will recalculate the node positions as well.
Just make sure you note this behaviour of collider.bounds: Removing obstacles with updateGraphs()

You could also make sure that obstacles are not included in the height testing mask in the grid graph settings.

Hi Aron!

Thank you for the fast reply!
I disabled the boxcollider and called the same code as the start and it WORKED. Thanks!

If others have the same problem as I had I used this code to remove a GameObject with a BoxCollider and update the GridGraph:

hit.collider.gameObject.GetComponent<BoxCollider>().enabled = false;
GraphUpdateObject ob = new GraphUpdateObject(hit.collider.gameObject.GetComponent<BoxCollider>().bounds);
AstarPath.active.UpdateGraphs (ob);
Destroy(hit.collider.gameObject);

Thanks again Aron for the fast reply and your answer!

PS: I really enjoy this Pathfinding asset you’ve made, keep up the good work!

1 Like