Hi,
I’m updating the graph with “AddWorkItem” and a “CalculateConnectionsForCellAndNeighbours” after that. The problem is that the next section of my code doesn’t reconise the changes.
For testing purpossed I made my code a “IEnumerator” and made it wait one frame after I updated the grid. Then it works fine.
My question, is there a way to make my code wait until Astar is done updating en recalculating the grid?
My code: (for a single position and a list op positions)
public void UpdateRoomGrid(List<Vector3> positions, bool walkable)
{
for (int i = 0; i < positions.Count; i++)
{
UpdateRoomGrid(positions[i], walkable);
}
}
public void UpdateRoomGrid(Vector3 position, bool walkable)
{
AstarPath.active.AddWorkItem(new AstarWorkItem(ctx => {
var node = roomGrid.GetNearest(position).node;
node.Walkable = walkable;
var n = node as GridNodeBase;
roomGrid.CalculateConnectionsForCellAndNeighbours(n.XCoordinateInGrid, n.ZCoordinateInGrid);
}));
}
Thanks