How to make a user loaded tileset

Godot Version

4.5.1

Question

I have a very simple texture atlas for my puzzle game, and I am adding a system to allow unlockable skins for the game, it’s as easy as changing a variable in the script to the ID of the tileset I want to use but some of my playtesters wanted to make their own skin for the game after seeing how simple the texture file is, so without having to rebuild the game every time they want to try out a skin they made (and i’d like to make this a feature for users too), I’d like to just have the game look for a file called tileset.png beside the binary and load it in as a new tileset using the same region settings as the other atlas’s, but I can’t seem to figure out how to load a texture into a tileset specifically. Ideally i’d like to set a ‘custom’ tileset that’s on id 99 and that’s where I load an external png to.

You can use a ResourceLoader to load a file as resource from a user:// directory and then replace your original texture atlas with it.

1 Like

From reading, it seems like i’d want to do something like

`custom_tileset = ResourceLoader.load("user://tileset.png", "TileSetSource")
TileSet.add_source(custom_tileset, 99)`

Though godot is giving me an error of

Invalid argument for “add_source()” function: argument 1 should be “TileSetSource" but is “TileSet”.

Is this not the right way to do it?

You need to create the source object and then assign the bitmap to it:

var tss: TileSetAtlasSource = TileSetAtlasSource.new()
tss.texture = ResourceLoader.load("user://tileset.png")
tile_set.add_source(tss, 99)

Or just create it in the editor and at runtime get its source object and re-assign the texture property.

1 Like

AH okay I got it working, turns out I was being a dork and trying to do this on a scene that doesn’t have any of my tilesets I defined on it. I just grabbed a tilemaplayer reference and added .tile_set to pass it in, looks like

func load_custom_skin():
	var tss := bg_layer.tile_set.get_source(99)
	tss.texture = ResourceLoader.load("res://tileset.png")

After making a tile source at id 99.

Probably cleaner ways to do it but it works, thanks!