Hi,
I’ve written two functions to mark an area as “walkable”, and am getting different results in terms of the nodes contained in passed bounds.
I initially wrote “markWalkable2” before I discovered the GraphUpdateObject. It obtained exactly the nodes I expected (e.g. for a Bounds of Bounds(Vector3(0,0,0), Vector(1,0,1)) I get exactly 1 node), however when calling this function while the game was running I was obviously stomping on some run-time data structure because it would occasionally blow up.
So I re-wrote it as “markWalkable”, which is lifted pretty much from the example code, however more nodes than I would expect are affected. It’s like the bounds have been expanded a bit, so the neighbours are being marked too, which is undesirable.
What am I doing wrong?
For the time being, I’ve reverted to using markWalkable2, which is crashy but exactly correct.
`
public void markWalkable(bool walkable, Bounds bounds, bool doNow = false) {
GraphUpdateObject guo = new GraphUpdateObject(bounds);
guo.modifyWalkability = true;
guo.setWalkability = walkable;
AstarPath.active.UpdateGraphs(guo);
if (doNow) {
AstarPath.active.FlushGraphUpdates();
}
}
public bool markWalkable2(bool walkable, Bounds bounds) {
if (null != gridGraph) {
if (null != gridGraph.nodes) {
List<Node> nodes = gridGraph.GetNodesInArea(bounds);
GridNode node;
for (int i = 0, c = nodes.Count; i < c; ++i) {
node = nodes[i] as GridNode;
node.walkable = false;
}
for (int i = 0, c = nodes.Count; i < c; ++i) {
node = nodes[i] as GridNode;
node.UpdateConnections();
}
Pathfinding.Util.ListPool<Node>.Release(nodes);
AstarPath.active.DataUpdate();
return true;
}
}
return false;
}
`