Okay, so I did some more testing.
I extended the bounds by a few units and now there is some effect, though not exactly what I would expect.
-
When I use RevertFromBackup() it works pretty well. However this has an inavoidable issue that if there is a change A, then an overlapping change B, then I revert change A and then revert change B then I will likely get some artifacts from the change A on the map, since the “backup” of B contains some data from the overlapping change A.
-
Therefore I’d really prefer to use modifyWalkability=true, setWalkability=true. This would more likely set some nodes as walkable where they shouldn’t be, but I prefer that compromise to the above one. So I tried with the very same bounding boxes and I get kind of artifacts (see the picture attached).
I don’t really understand why - I would expect that the method that I use would rather have too many nodes set to walkable rather than too few.
Here is a relevant part of the code:
var newWalkability = <something>;
var oldWalkability = <something>;
if (<some condition expressing essentially that it is necessary to update the graph based on whether newWalkability and old walkability differ>)
{
if (OldGUO != null)
{
Debug.Log("Revert: " + OldGUO.bounds.center);
AstarPath.active.UpdateGraphs(OldGUO);
OldGUO = null;
}
GUO = new GraphUpdateObject();
if (newWalkability)
{
GUO.modifyWalkability = true;
GUO.setWalkability = true;
GUO.updatePhysics = false;
}
else
{
GUO.modifyWalkability = false;
GUO.updatePhysics = true;
}
var bounds = gameObject.GetComponent<Collider>().bounds;
// Extend the bounds so they overlap y-axis
bounds.size = new Vector3(bounds.size.x, bounds.size.y + 2f, bounds.size.z);
bounds.center = new Vector3(bounds.center.x, bounds.center.y - 1f, bounds.center.z);
GUO.bounds = bounds;
if (!newWalkability)
{
Debug.Log("Unwalkable: " + GUO.bounds.center);
}
if (!newWalkability)
{
OldGUO = new GraphUpdateObject();
OldGUO.modifyWalkability = true;
OldGUO.setWalkability = true;
OldGUO.updatePhysics = false;
OldGUO.bounds = GUO.bounds;
}
else
{
OldGUO = null;
}
AstarPath.active.UpdateGraphs(GUO);
I verified though logging that any “Unwalkable” line has it’s appropriate “Revert” line, so it’s not the issue with that.
