title: Detect which Tilemap cells have collided with a Collider2D in Unity
body: <p>I have a <code>Tilemap</code>. This has a <code>TilemapCollider2D</code> component. Onto this are painted several tiles that each have their own sprite collider shape. However they are sprite tiles not prefabs. (They were not painted using the Prefab Brush.)</p>
  <p>I also have a game object with a <code>Collider2D</code> (a <code>CircleCollider2D</code> in my case) with <code>isTrigger</code> set to <code>true</code> and no <code>Rigidbody2D</code> attached as this game object stays at a fixed position relative to its parent.</p>
  <p><em>[EDIT: I discovered that this collider is actually using the <code>Rigidbody2D</code> of the parent game object. Without any rigid body, collisions wouldn't be detected at all.]</em></p>
  <p>When the <code>Collider2D</code> enters/exits a tile, how can I identify the grid coordinates (<code>Vector3Int</code>) of that tile?</p>
  <p>To be clear, I want to detect this from the Tilemap script. i.e. <code>TilemapCollider2D.OnTriggerEnter2D()</code> or <code>TilemapCollider2D.OnCollisionEnter2D()</code>.</p>
  <p>For example, in the picture below, I would want to have received <code>OnTriggerEnter2D()</code> for tiles B, C, D &amp; E and to know their positions in the grid.</p>
  <p><a href="https://i.stack.imgur.com/vyVes.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vyVes.png" alt="Circle collider overlapping with tiles B, C, D &amp; E" /></a></p>