Deleting a GraphUpdateObject

Hello,

If this code updates the graph when adding a new blocking object:

    Bounds bounds = newObj.GetComponent<Collider>().bounds;
    GraphUpdateObject guo = new GraphUpdateObject(bounds);
    AstarPath.active.UpdateGraphs(guo);

How do I go about updating the graph when removing said object? Do I delete guo object and update graphs, or just delete the object from scene, and do:

    AstarPath.active.Scan();

Am worried that the latter solution may not be very efficient in some cases.

Hi

You can use almost the same code. A GraphUpdateObject (with the default settings) only requests that the graph should be recalculated in a particular region and that works for both adding obstacles and removing them:

// Add
Bounds bounds = newObj.GetComponent<Collider>().bounds;
GraphUpdateObject guo = new GraphUpdateObject(bounds);
AstarPath.active.UpdateGraphs(guo);

// Remove
Bounds bounds = newObj.GetComponent<Collider>().bounds;
GraphUpdateObject guo = new GraphUpdateObject(bounds);
Destroy(newObj.gameObject);
AstarPath.active.UpdateGraphs(guo);
1 Like

Thank you for the code snippet. I am noticing an issue, however, where deleting an object is causing nearby nodes to be walkable, if they were not before. Please see related post: Object bounds causing neighbor tiles to be walkable/unwalkable