Adding a column to my Tileset PNG ruined my Map

A general part of my workflow with Tiled is adding new tiles to existing Tilesets. I do this by increasing the width of the png in aseprite by 32 pixels to the right, and then add the new tiles and save it again. I get a popup in Tiled about the png changing and accept it, and it has always worked great. I just did this again and it worked fine, but then I opened another tilemap that uses the same tileset, and all its tiles were swapped with other tiles in the tileset. I cannot find a way to fix this.

As you can see, they use the same Tileset, and for the smaller battle map, everything remained fine. But for the larger map, all the tiles changed. I dont see how this is possible.

In “Based on Tileset Image” tilesets, tiles are assigned IDs in rows starting from the top left going rightward, then continuing to the next row, and so on. When you change the width of the image, the numbering is done the same way, but many tile IDs past about the first row’s worth end up assigned to different tiles.

I have no idea how the smaller map remained unchanged, except that perhaps it only used tiles from the first row, or perhaps uses a different copy of the tileset? (Edit: Or perhaps somehow its copy wasn’t refreshed in memory after resizing? In this case, it’ll break if you reload the Project or reopen Tiled.)

I’ve previously written in more detail on this topic in the Tiled Tip Sheet, including tips to avoid the need to resize your tileset, and how to fix your maps if you must resize it.

There’s also a planned new Tileset type where tile IDs are assigned to specific, defined regions within the image, these would remain stable when the image is resized, at the cost of making it potentially more annoying to define the tiles. Change tileset definition to avoid renumbering tiles when image width changed · Issue #2863 · mapeditor/tiled · GitHub

Thank you for the response, is there any way for me to fix this? I understand in the future I shouldnt add width, even though it has always worked for me until this one time. Its strange because I added 32 pixels to the width, added some tiles saved it, then decided against those tiles and undid those changes, so the tileset itself is the same as it was when it was working with both maps. So I think i just experienced some strange bug with the larger map that made it start referencing empty tiles in the set, or everything was offset somehow? What I dont get is SOME of the tiles are still correct, but a lot arent. The smaller map remains unchanged even after reloads. They both use the exact same tileset. The only thing I can think of is I was working on the smaller map when I hit “yes” on the popup that comes up when you change the png for the tileset.

If you experienced a bug, it would’ve been before, because what you’re seeing this time (the “corrupted” map) is the expected behaviour. Oh! Another possibility is that if you had Tiled running while doing the previous resizes, you answered “yes” to Tiled’s prompt to fix open maps, but not this time, or maybe this time you resized while Tiled didn’t have some of the maps open, so some maps were updated/fixed and some were not. I completely forgot this option in Tiled, I should really mention it in the tip sheet.

The tip sheet section I linked describes ways to fix the tiles after the fact. It’s easiest to fix them with the script it linked if you bring back the working tileset width and create a new tileset for the new width, and then do the replacement. However, if you currently have some maps in a working state and some in a non-working state, you’ll need to be careful about which ones you adjust and how. It may even be easier to start over, if you don’t have many maps.

Here’s the thing: unfortunately the remapping of tile IDs is currently limited to open files. It sounds like you didn’t have your other tilemap open at the time, so its tile references have not been adjusted.

If you still need to fix up this map, it’s a little tricky but it could be done as follows:

  • Open Tiled with just the affected tileset open (no maps)
  • Outside Tiled, replace the tileset image with the old version (or just with an image that had the same amount of tile columns as the old one).
  • Tiled will ask to adjust the tile indices: answer Yes (this temporarily remaps potential data associated with your tiles to the old state, so we can answer Yes again later)
  • Now open the broken map (if you used the old version of your tileset image, it should actually no longer look broken)
  • Outside Tiled, replace the tileset image again with the new version.
  • Tiled will ask to adjust the tile indices: answer Yes.

That should take care of the broken map. Now you can also open the map that had already been adjusted, and it should still look fine.

Going forward, the plan to improve this situation is as @eishiya pointed out to write each tile’s region in the tileset file, so the tile IDs can stay stable even when changing the columns (and the regions can be moved as needed to adjust to reorganized tilesets). Another feature that would help, is when the tile indices adjustment could be triggered manually for any asset rather than needing to be triggered by replacing image files in the right moment.

Until the above improvement have been made and when you still feel confident in relying on the current popup, what you need to do is to make sure all maps using that tileset are open in Tiled when you save the updated tileset image, as well as to make sure you save the tileset and all maps after the adjustment has been done.