Consolidate multiple tilesets?

I have a problem where my maps are using tiles from several of duplicate tilesets – I opened maps from my last game and modified them for my new game. I didn’t notice that it had multiples of the same tileset until too late. Is there any way to delete the duplicates – and tell it to use just one tileset?

Within Tiled there is unfortunately no way to do this. However, it should be possible to edit your map file in a text editor and simply change the path used to refer to the tilesets to the one you want the map to use. You’ll end up with the same tileset being mentioned several times in the map file (with different “firstgid” values), but that should go away when you load and save the map in Tiled.

Note that I didn’t try this, so be sure to have backups and let me know if it works!

Okay, thanks. I don’t think that works – the maps already used the exact same name. I think I had tried that before at some point. But I was able to resolve the issue by removing the second reference in the file. When I loaded the map, then I could just go through and replace the tiles wherever a red square with an x appeared.

I didn’t mean the name, I was talking about the file path (the source attribute).

That of course works, but it could be a lot more effort.

Yes I was also talking about the path. Luckily I did not have many tiles which used the duplicate, so it wasn’t a big deal.

I’ve ran into the same issue and it doesn’t really hurt, but it still bothered me.
So much so that I created an application to merge tilesets:

You can download it from the releases page:

Let me know if this worked for you!

Would you mind adding to the readme some information about what it takes as inputs, and what it outputs? From this thread, it sounds like this is about finding and resolving duplicate tilesets, but from the name of the application, it sounds like it’s about taking maps and merging their multiple tilesets into a single tileset.

Also, regarding the other layer data formats: I’m not sure what exactly this program does, but it sounds like it might be something that could be implemented as a Tiled script, in which case you wouldn’t need to worry about the layer data formats at all, and you could get “free” support for all map formats that Tiled can read, not just TMX.

Honestly I am a noob with Tiled and I don’t know anything about other formats than TMX. I also didn’t know Tiled supported scripts, as that actually sounds like a better deal to me than what I wrote. Or did you mean commands? (also something I didn’t know about until just now)

Inputs/outputs wise, for now I created a simple standalone console app that doesn’t even take parameter inputs. I’m planning on looking into that in the future, but as it solved the problem for me I decided to put it out there. Now that I know commands are a thing in Tiled, I could look into that as well.

The program does what OP asks for; it merges duplicate tilesets into one tileset (in a new, single .tmx file, so it leaves the original file alone).
It is totally standalone from Tiled and it should be run separately.

The program updates the value of tiles used in other (duplicate) tilesets, with the positions of the first tileset.
So let’s say I have tileset A with tiles 1-10 and tileset B with tiles 11-20.
Now assume that tile 3 from tileset A was used and tile 14 from tileset B.
The program updates tile 14 with 4 as it then refers to tileset A.
Then there’s no references to tileset B anymore and it can be safely removed.

I updated the readme with some notes. I’ll also think of a new name :stuck_out_tongue:

Thanks for the clarification! I think it might be good to specify in the description and readme that it merges duplicate tilesets. Without that keyword, “merge tilesets” is easy to interpret as something else xP

And I meant scripts :] Tiled has been scriptable with JavaScript since version 1.3: Scripting — Tiled 1.10.2 documentation
With scripting, it’s quite simple to iterate all the tilesets in a map, check if they’re a “based on tileset image” tileset, check their image source and tile size, and replace duplicates with a single “original” tileset - it would then be up to the user to decide whether they want to save the modified map or not, and they could Undo the change if they don’t want it.
It would also be possible to write additional actions to do this to all open maps, or to all the maps in a project, and to have all of them be unified consistently, rather than merging to the first tileset within each map.
You wouldn’t even have to look at the tiles in the map at all, since TileMap.replaceTileset(old, new) will take care of updating the tiles for you.

Updated project name: Releases · TomONeill/tmx-tileset-deduplicator · GitHub

That’s very cool, thanks for the link and information!

1 Like