I made a short video showcasing the issue: Astar Grid Update Issue - YouTube
- As you can see when starting the game the graph and path are generated correctly (see the green line in game view/the green circle moving)
- If I click on a tower button the build mode gets activated. The red tiles are the ones on which a new tower can be build. Currently only the blocking logic is used so existing towers dont count for this.
- As you can see it successfully identifies the tiles that cant be walked on (the ones without the red outline)
- If I cancel the buildmode and start it again, the tiles are also correctly identified.
- If I build a tower, the graph and path are updated correctly. graph see scene view and path see play view.
- If I now enter build mode again, the tiles are no longer being identified correctly. As you can see the tile in the top left for example is flagged as buildable eventhough its clearly blocking.
- On the other hand the tile at position 0,2 is correctly flagged as blocking
- Every further time I build a tower in a non blocking tile and activate build mode again, it will show the exact same tiles as buildable/non buildable
- If I build a tower on a blocking tile it will show almost everything as blocking
My code currently looks like this:
public bool isBlocking(GridPosition gridPosition, TowerData towerDataToBuild)
{
var tower = towerDataToBuild.towerPrefab;
var towerCollider = tower.GetComponent<BoxCollider2D>();
var center = (Vector3)gridPosition.WorldPosition;
var size = (Vector3)towerCollider.size;
var colliderDepth = 100f;
var sizeScales = size.Set(z: colliderDepth);
var guo = new GraphUpdateObject(towerCollider.bounds) {
bounds = new Bounds(center, sizeScales)
, modifyWalkability = true
, setWalkability = false
};
var spawnPointNode = AstarPath.active.GetNearest(spawnerTile.transform.position).node;
var goalNode = AstarPath.active.GetNearest(destinationTile.transform.position).node;
var notBlocking = GraphUpdateUtilities.UpdateGraphsNoBlock(guo, spawnPointNode, goalNode, true);
return !notBlocking;
}
I really dont know where to go from here.
It would be greatly appreciated if you at least could give me a pointer in what direction I should investigate.