GraphUpdateObject vs GetNodesInArea node difference

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;
}

`

I looked closely at the GridGenerator.UpdateArea() code and it’s doing a lot of stuff I don’t need, furthermore it expands the affectRect by 1, which is causing the problem.

I’ve rewritten it for my case to be simpler (just takes walkability into account), but the important thing is that I only expand the bounds for the connection calculation.

Hope this helps someone.

` public void UpdateArea(GraphUpdateObject o) {
List nodesInArea = GetNodesInArea(o.bounds, null);
if (null != nodes) {
GridNode node;
//Mark nodes that might be changed
for (int i = 0, c = nodesInArea.Count; i < c ; ++i) {
node = nodesInArea[i] as GridNode;
o.WillUpdateNode(node);
}
//Apply GUO
for (int i = 0, c = nodesInArea.Count; i < c; ++i) {
node = nodesInArea[i] as GridNode;
node.walkable = node.WalkableErosion;
o.Apply(node);
node.WalkableErosion = node.walkable;
}

			Pathfinding.Util.ListPool<Node>.Release(nodesInArea);
			// Expand the bounds by one to take outside connections into account

			Bounds updateBounds = new Bounds(o.bounds.center, o.bounds.size);
			updateBounds.Expand(1);
			nodesInArea = GetNodesInArea(updateBounds, null);

			//Recalculate connections
			for (int i = 0, c = nodesInArea.Count; i < c; ++i) {
				node = nodesInArea[i] as GridNode;
				CalculateConnections(node);
			}
			Pathfinding.Util.ListPool<Node>.Release(nodesInArea);
		}
	}

`

It would be really helpful if the expansion of the bounds could be an option. As it stands, I have to replace the UpdateArea() function each time I start a new project using A* or get an update.