Changing node walkability to true when the walkability was false problems

I am working on a tower defense where you can build the towers on the path of the creeps. When I build a tower I set the nodes walkability to false so the creeps cannot walk through the tower. When I sell the tower and update the nodes to walkability = true. The graph does not update and allow the creeps to walk along those specific nodes. I tried adding the penalty also to 0. But it still does not work when I sell the tower. IT DOES WORK however when the creep detects that the path is blocked to the waypoint and the creep destroys the tower(s) around it. Should I do a scan after each time you sell a tower? (slows down play) Or is there some other way?

building tower code:
//b1 is the tower
GraphUpdateObject guo = new GraphUpdateObject (bl.buildingGameObject.collider.bounds);
guo.setWalkability = false;
AstarPath.active.UpdateGraphs (guo);

selling tower code:
//hitColliders[I] is any tower within the radius
//the method used is a splash damage method
//but this radius is small so only the one tower is destroyed
//it destroys the tower but does not update the graph
if (hitColliders[i].tag == “Tower”) {
Destroy (hitColliders[i].gameObject);
GraphUpdateObject guo = new GraphUpdateObject (hitColliders[i].collider.bounds); guo.setWalkability = true;
guo.addPenalty = 0;
AstarPath.active.UpdateGraphs (guo);
}

Unit blocked code:
//same code as up there^^
//this code updates the graph and allows the units to walk through those nodes
if (hitColliders[i].tag == “Tower”) {
Destroy (hitColliders[i].gameObject);
GraphUpdateObject guo = new GraphUpdateObject (hitColliders[i].collider.bounds);
guo.setWalkability = true;
guo.addPenalty = 0;
AstarPath.active.UpdateGraphs (guo);
}

Hi

On a GraphUpdateObject, the flag “modifyWalkability” needs to be set to true, otherwise it will not set all nodes to have the walkability of the variable [setWalkability] (I know the variables do not have the most obvious names).

/** If true, all nodes \\a walkable variables will be set to #setWalkability */ public bool modifyWalkability = false; /** If #modifyWalkability is true, the nodes' \\a walkable variable will be set to this */ public bool setWalkability = false;

Thank you, it works exactly how I want it to now!

1 Like