All nodes walkable, procedurally generated 2D tilemap

Hi,

I am making a top down dungeon crawler game that procedurally generates the map at the start of every game. I am storing the tiles using Unity’s tilemap function, one for the floor tiles and one for the walls. The walls have a Tilemap Collider 2D component attached. I have created an empty game object named “A*” and attatched the AstarPath component to it. I created a grid graph and adjusted it to match the size of the dungeon. I set both the obstacle layer and the layer of the wall tilemap to ‘TransparentFX’. Once the dungeon tiles have been generated and added to the tilemaps I have called AstarPath.active.Scan(); .

The problem is that when I run the program, all of the nodes are walkable. I have tried to find a solution to this on the forum but nothing has worked for me so far. The ‘align with tilemap’ button doesn’t appear in the inspector, so I suspect that it may not be able to detect the tilemap for some reason. Any help would be appreciated.

I have tried to attach below any relevant screenshots of my project



Does your walls Tilemap have a Tilemap component on it? I only see the Tilemap Collider in your screenshot. I wasn’t able to reproduce this, but mine has the Tilemap, Tilemap Collider, and Tilemap Renderer on it. All these are on a GameObject that has a parent with the Grid component on it. What’s your set up look like outside the “Tilemap(wall)” GameObject?

The wall tilemap does have the Tilemap and Tilemap Renderer components on it, yes. Both of the tilemaps are children of the Grid gameobject, I attached a screenshot of my hierarchy.



image
image

That’s correct. For grid graphs, you’ll have to put colliders to make certain regions unwalkable.
Recast graphs, on the other hand, can detect the abscence of any tilemaps and make that an obstacle too. This is not possible for grid graphs at the moment.

Are you using the latest version? Based on your screenshot it looks like you are using an older version.

How would you suggest going about adding colliders to the walls, Is the Tilemap Collider 2D component not enough?

When I tried to recreate this issue, I simply added a Tilemap Collider to the object with the Tilemap component, tagged it, and had no issues getting only those tiles to be found unwalkable. So yeah, I only needed that one component

I found that when I used the Scan button during runtime the graph was scanned correctly, meaning that AstarPath.active.Scan() was the issue and not the tilemap. I found a few similar issues in the forum, and after adding WaitForEndOfFrame() before scanning, the walls are now marked as unwalkable.

Thanks to you and Aron for taking the time to help :slight_smile:

2 Likes