Having trouble eroding GridGraph

Hi, I’m using a GridGraph for pathfinding in a 2d, tilemap based game where I dynamically generate the map. To make this work, I just mark nodes in the graph as unwalkable as I generate them, if they are indeed obstacles. I wanted to use erosion to make the AI avoid walking directly into walls where possible, but it doesn’t seem to actually be setting the tags. After setting all the nodes walkability, I am explicitly calling ErodeWalkableArea().
Here are my grid settings:
GridSettings
And here is the resulting map (Excuse the programmer art):


I have Graph Coloring set to tags in the settings (the other colorings seem to work).

1 Like

Hi

Do you have ‘Show Surface’ enabled on your grid graph? I can’t see any nodes in your second screenshot.

1 Like

I do have ‘Show Surface’ enabled. I didn’t even notice at first that the nodes and outlines weren’t visible any more.
They show up, along with all the tag coloring I want to see if I click ‘Scan’ in the inspector, but that won’t really work in my case, the built in scan doesn’t mark nodes walkable how I want to (so instead I’m doing that programmatically). Setting the dimensions of the grid, scanning, then setting the walkability seemed to work… but calling ErodeWalkableArea after all that seems to do nothing.

I figured it out!
My issue was that I needed to manually loop through the nodes in the graph, calling CalculateConnections(), after having set all my wall tiles unwalkable manually. Only then did the erosion work.
Another issue may have been that, in my initial call to Scan() (that i do just to generate the nodes in the first place), it was doing erosion incorrectly, as I did not yet have my unwalkable nodes set up. easy fix was to just leave erodeIterations at 0 until after the scan.

Overall, I’m very happy with the package, but I do think some better documentation/process for manually setting up a grid graph would be nice :wink:

1 Like