I have been working on getting a setup I like for a simple map for a small hobby project. For better or worse, my current flow is to have a single layer map in Tiled where I can draw the general shape of my map. I then import that map into Unity using SuperTiled2Unity.
The issue comes with when I then try to “duplicate” that single layer into a new tilemap inside of unity via code. For a number of reasons, I do not want to have two layers in Tiled. I want to simply duplicate a single map during import to Unity onto a separate Tilemap. I am using a custom importer script with SuperTiled2Unity, but that shouldn’t have much of an impact on my question as it is more about how Tile positions are represented in Tiled compared to Unity.
So with my goal in mind of duplicating the map from Tiled into a separate Unity Tilemap (while maintaining the imported Tilemap as well), here’s the core of my issue:
In my custom importer script, I am basically doing the following steps:
- Get the object that represents my single layer Tilemap that is coming from Tiled
- Create a new GameObject with a Tilemap component programatically (this game object has the same position as the imported Tilemap mentioned in the previous step) that is a child of the same Grid that the reference tilemap is a child of.
- Loop over all Tile positions in the reference Tilemap (from the first step)
- For each position, set the tile in the same position on my new Tilemap to a simple tile.
From the code, I would expect the two tilemaps to be exactly the same (except for the tiles that they are comprised of) and be perfectly aligned on the grid. However, what I get is what you can see in this image:
In the above, the orange tiles are from the reference tilemap and the pink tiles are from my “duplicate”. As you can see, the duplicate is off by 0.5 on the X and Y axes. I’m confused by this. I have played around with the Tile Anchor and such to no avail.
In my head, this feels like it is a difference between how Tiled identifies a Tile’s position in the Grid and how Unity places a tile within a grid. Why are they not the same if the Grid is the same Grid and the “position” of each tile is the same??
I would appreciate any insight into this, and thank you in advance!