Is there a way to change the tile sets sprite that gets used via a tilemap inside code? I already have a workaround about this, but if there was a way to directly change the sprite the tileset draws from it would make everything alot faster to work on. I currently have around 16 tilesets and 16 sprites that they draw from, every single sprite that gets used by the tilesets are at the same place as the others (trees are ontop of other trees, ground tiles ontop of ground tiles etc), so it would make my life so much easier if i could just change the one that gets used directly and not edit all 16 tile sets every time i wanted to make a slight change in the sprites. Much appericiated!
How do i change a tile sets sprite via code?
If you have already set up a Tileset in TileMap, you can change the image by following the instructions below.
Operation Procedure)
- Load the texture you want to change.
- Get the tile_set property of Tilemap.
- Call the tile_set.tile_set_texture function and specify the tileset number and texture you want to change.
Example)
var new_texture = load("res://new_tileset_texture.png") $Tilemap.tile_set.tile_set_texture(0, new_texture)
Reference)
https://docs.godotengine.org/en/stable/classes/class_tilemap.html#class-tilemap-property-tile-set https://docs.godotengine.org/en/stable/classes/class_tileset.html#class-tileset-method-tile-set-texture
*) Note that changing the tileset will affect the entire TileMap, not a specific tile.
- Edited
@MizunagiKB said: If you have already set up a Tileset in TileMap, you can change the image by following the instructions below.
Operation Procedure)
- Load the texture you want to change.
- Get the tile_set property of Tilemap.
- Call the tile_set.tile_set_texture function and specify the tileset number and texture you want to change.
Example)
var new_texture = load("res://new_tileset_texture.png") $Tilemap.tile_set.tile_set_texture(0, new_texture)
Reference)
https://docs.godotengine.org/en/stable/classes/class_tilemap.html#class-tilemap-property-tile-set https://docs.godotengine.org/en/stable/classes/class_tileset.html#class-tileset-method-tile-set-texture
*) Note that changing the tileset will affect the entire TileMap, not a specific tile.
Okay so, i have tried what you have put in, but it appeared that it only changed the first tile i defined, so i found a workaround it with: for i in 4: plate_instance.tile_set.tile_set_texture(i, "load path here") that did make everything work, but if you coildnt tell im summoning multiple of these tiles, and whenever it changes from "PlateGreen" to "PlateLime" for example it changes every single one of them to the new sprite! (the desired effect should be it only changing the sprite of those i have just summoned from that point onward, not the ones i have made already) The answer may lie within making all of the tilesets unique when i summon them so they change only themselves, but regardless, how can i fix this?
Okay, after a bit of googling, i managed to fix it! all i did was put the following line ontop of the tile_set_texture()
line:
plate_instance.tile_set = plate_instance.tile_set.duplicate()