Trouble working with Composite Tilemap collider. eg. ClosestPoint doesn't work

I’m wanting to perform manual overlap tests of scenery. In my test scene which is random closed-rectangle walls, I have a tile-map that I use with a composite collider. Without enabling the composite, the collider works as expected, allowing me to find the closest point on it and reporting overlaps. Enabling the use of the composite collider, Physics2D calls fail with any results. My closest point test reports the point I’m testing for and I don’t get any overlaps reported.

On the left side, we see the tilemap collider; the red dot shows the closest point to the agent (under the camera icon). Console shows overlaps results of the agent with the scenery and the scenery with the agent (tilemapcollider2d.overlap(…)).

On the right, the the agent is testing positive even in space. The compositecollider doesn’t report any overlaps with the agent.

Hi!

I had the same issue and used the following workaround. Instead of using ClosestPoint on the original TilemapCollider2D, I used that method on its composite property. Like this:

Vector2 closestPoint = tileMapCollider.composite.ClosestPoint(point2D);

I suspect it works like this because the original collider doesn’t have bounds set up properly (I can see in the debugger that they are all zeros).

1 Like

That works. Nice one!

So instead of accessing the CompositeCollider2D component, you access the TilemapCollider2D.composite component. Which is counter-intuitive as to use the composite function of the tilemap, you have attach a Composite Collider component, but this is not the route to access it. ¯_(ツ)_/¯