Find position of tile collision OnTriggerEnter2D

How do I find the collision position of a tile when using triggers?

All I seem to be able to get hold of is the collision game object which is obviously the entire tilemap rather than the actual tile I have collided with.

This is my code so far

private void OnTriggerEnter2D(Collider2D collision)
    {
        if (this.GetComponent<Collider2D>().IsTouchingLayers(LayerMask.GetMask(new string[] { "FuelCell" })))
        {
            Tilemap map = collision.gameObject.GetComponent<Tilemap>();
            Vector3 hitPosition = Vector3.zero;
            if (map != null)
            {
              
                    map.SetTile(map.WorldToCell(collision.transform.position), null);
                
            }
        }
    }

Hey @coolblue2000,
I was trying to do the same thing and found that I was only getting the world position of the tilemap center. I approached this from another angle and used the position of the player to find the location then put this in a OnTriggerStay2D statement. I used a OnTriggerStay2D because I was finding that using OnTriggerEnter2D would cause an adjacent cell to be replaced because the center of the collider on the player was in the bounds of the adjacent cell.
See example code below. Hope this helps.
Note: If you are looking to be more accurate than this you may need to grab the grid (parent object of the tilemap) or use the worldtocell with a vector3 that is offset by the movement direction of the player in such a way that you can be sure you are plotting closer to the center of the cell you wish to remove.


private void OnTriggerStay2D(Collider2D collision)
{
    if (collision.tag == "Resource")
    {
        Tilemap map = collision.GetComponentInParent<Tilemap>();
        Vector3Int removePos = map.WorldToCell(transform.position);
        map.SetTile(removePos, null);
    }
}