superTiled2Unity - Getting tile from world location

Hi.
I’m having a difficult time tracking this down.
Im using SuperTile2Unity and Unity (of course). I have my maps with layers rendering, etc.

How do I get a tile based on a world location? Im not familiar with Unitys TileMap either, so tonight I will be reading those docs. But I wanted to post here first.

For example: I have a OnTriggerEnter2d( Collider2D collision)

How do I get the Tile (s) across all layers for collision.transform.position?

Thanks

Hi
Figured it out. Took me a bit to realize SuperTile2Unity extends the Unity TileMaps. Once I figured that out it was easy. Sure explains why I was so confused that SuperUnity2Tiled was missing simple queries to get back tiles haha.

For those who make the same newb mistake I did:

    var tileMaps = FindObjectsOfType<Tilemap>();
    int i = 0;
    foreach ( var tm in tileMaps )
    {            
        Vector3Int cellPosition = tm.WorldToCell(transform.position);
        cellPosition.z = 0; // Z plan of tiles, might vary for you.
        var superTile = tm.GetTile<SuperTile>(cellPosition);
        if (superTile != null)
        {
            System.Diagnostics.Debug.WriteLine("[Layer: " + i + "] Found Tile named: " + superTile.name);
        }
        else
        {
            System.Diagnostics.Debug.WriteLine("No Tile for layer " + i);
        }
        i++;
    }
1 Like