- A* version: 5.3.1
- Unity version: 2022.2.21f1
Hello,
When upgrading to version 5.3.1 from 4.3.73 I have found that the ErodeWalkableArea() function of the GridGraph has disappeared, and in the upgrade documentation I have not found an equivalent function. Previously, I was doing the following:
public void CalculateWalkableTiles()
{
AstarPath.active.AddWorkItem(new AstarWorkItem(ctx => {
var gg = AstarPath.active.data.gridGraph;
for (int z = 0; z < gg.depth; z++)
{
for (int x = 0; x < gg.width; x++)
{
GridNodeBase node = gg.GetNode(x, z);
var isWalkable = false;
if (node != null)
{
// Make my walkable logic here
}
gg.GetNode(x, z).Walkable = isWalkable;
}
}
gg.GetNodes(node => gg.CalculateConnections((GridNodeBase)node));
gg.ErodeWalkableArea();
}));
Now I know I have to change the line of CalculateConnections to gg.RecalculateAllConnections(), but I can’t find how can I tell my GridGraph to erode the area using the new walkable tiles, and it’s not recalculating it automatically. What’s the equivalent in this new version?
I can’t say for certain but I did find this Job that seems to do the same? JobErosion
The description says:
Calculates erosion.
Note that to ensure that connections are completely up to date after updating a node you have to calculate the connections for both the changed node and its neighbours.
In a layered grid graph, this will recalculate the connections for all nodes in the (x,z) cell (it may have multiple layers of nodes).
Hello,
Could you provide more info on how to use that? I can’t see much documentation about it. I’m digging through the library code and I have seen it’s used inside Erosion of GridGraphScanData, but this method is not documented at all.
As I understand from the documentation, should I be moving this code to a custom grid graph rule and then access this GridGraphScanData through the context? Also, the method Erosion ask for a erosionWriteMask and a erosionTagsPrecedenceMask, in which I don’t know what to pass.
Can you confirm if this is the only way to do it? It differs quite a lot from how I was dealing with it in version 4.3. If it is, then I would appreciate some guidance on the details of this Erosion method, because right now I’m not really sure if it’s intended for public or internal only use.
Thanks a lot for the help.
Hi
If you can, I’d encourage you to use the helper method GridGraph.SetWalkability
.
I don’t think this applies erosion, though.
If you want even more flexibility, I would recommend grid graph rules: Writing Custom Grid Graph Rules - A* Pathfinding Project
Then it will be very easy to make it work with graph updates, erosion, and even the ProceduralGraphMover.
If you use a grid graph rule you do not have to apply the erosion yourself. It will be applied automatically after your rule runs.
1 Like
Hello,
It took me a while to move the logic to a rule, but it’s indeed working now, and it automatically applies erosion after the walkability update.
As always, thank you both for all the help.