How do I integrate A* with 2D Toolkit's Tilemaps?

I have created a Tilemap in 2D Toolkit. I am trying to use the A* Pathfinding Project to move an object from one side of the map to the other. The problem I am facing is that when I run a scan to create my grid graph it appears to ignore the colliders in the tilemap. Does anyone have any advice?

Hi

If those are real colliders, put them in a layer included in the grid graph’s obstacle mask.
See http://arongranberg.com/astar/docs/getstarted.php

1 Like

I have gone through the getting started guide. I have a separate layer in my tilemap called “Platforms.” The graph’s obstacle mask is set to that layer. I have set the platform tiles up with a polygon collider. When I scan with a ray trace it shows the entire map as walkable. If I scan with a sphere collider it shows the entire map as unwalkable. Any suggestions as to what I am doing wrong?

Screenshot?

Are you sure the platforms are obstacles? Shouldn’t the player be able to walk on them?
Also, you might want to turn off Height Testing (if it isn’t turned off already), since this is 2D.

I know this is an old topic, but I want to help others that may have run into this issue. It isn’t immediately obvious, but for me the issue was using Physics 2D with the 2D Toolkit’s TileMap. The 2D Toolkit creates the colliders as 2D Edge Colliders in this case, and A* doesn’t work with 2D Edge Colliders due to probably a bug in Unity - some collision detection functions don’t take into account this collider type.

The way I got it working was to use Physics 3D in the 2D Toolkit. Set this up in the Sprite Collection under Settings. Then use Sphere colliders in A* with no height testing.

Oh, and before I forget, rotate the A* Pathfinder -90 degrees on the X axis.

Click on Scan, and you should be good to go.

1 Like

This is very old, but I stumbled upon this issue. The way to solve this in 2020 is by changing the Composite Collider 2D, property Geometry Type from Outlines to Polygons.

This change made A* consider the colliders in the tilemap.

3 Likes

This. I was beating my head against the wall and debating using a different tool but this fixed everything. Thanks for posting it.

1 Like

Confirmed in 2022, you need to change the composite collider to use Polygons. I found lowering the grid size to be slightly lower than the tilemap density and increasing the circle size in the path object was a necessary tuning after that as well.

1 Like