How to quickly set (copy and past?) tilemap terrain?

Godot Version



Hello ! I’m learning to use the new TileMap system of Godot 4, so far it’s pretty cool.
I have a first question regarding terrain system: I am using Tilesetter to quickly create an autotile for my project, Then, to properly use the autotile, I need to go to TileSet tab → select my Tileset → paint properties terrains then set terrains. I now have to paint the part of my terrain to use in the autotile, like in this screenshot:

Now, it is a tedious, weird process to paint this thing, and it’s especially frustrating because if you always use the same pattern for autotile, it’s basically always the same pattern to paint over, but it’s still long and confusing as you probably know. My question is simple: is there a way to not do it every time, and just save or copy/past the patten painted in another autotile into a new one? So far I have not found any way, but it seems like a logical thing to be able to do, since it’s basically always the same process (especially when you always use the same autotile pattern, which is most people’s case).

My second question is: is there a way to change the color of a tileset (not an entire tilemap, just a tileset)? I’d like to create some 1bit tilesets that are all gonna have white and as main color and then just change the color in code (a different one for each tileset).
I have not found any way to do so, weirly enough (might be because of the way tileset work?).

Thanks a lot for your help!

1 Like

To answer the first part of your question, I totally agree with you. One of the first things I did when I moved to Godot 4 was make TileBitTools, which should do just what you’re looking for. It has preset templates, and you can also make your own. (It’s archived because I wasn’t planning on actively working on it anymore, but it works in 4.2 and I will give it a quick update if it breaks in the 4.3 beta.)

For the second part, you should be able change the color with the per-tile modulate setting. For multiple versions, you can make alternative tiles, or just import your same source image more than once. If modulate isn’t sufficient, you can programmatically get your source texture’s Image, duplicate it, make changes using Image’s methods, and resave it. If you need even more complex changes than that, you can programmatically put the texture in a TextureRect in a Subviewport, apply a shader, and then save the Subviewport’s texture to use for your new tiles.

The TileSets are very accessible to scripting in 4.x, so you can then transfer all your tiles’ settings to a new TileSet source via script if it will save you time.

The code in TileBitTools does some image manipulation to create the previews and then programmatically assigns the terrain bits, so feel free to use any parts of that code that are helpful.

Edited to better explain the image options.


Ok thanks ! Not sure how to properly use the per-tile modulate setting yet, but I’ll figure it out.

One connected question about the tilemap terrain: I know how to create tiles in code and then use the set_cells_terrain_connect() function to make them terrain and have the autotile mapping, and then I also know how to “erase” a tile in code by setting its source_id to -1 using set_cell(0, tile, -1) but once the tile is “erased”, the other tiles dont change to keep the terrain mapping (basically it’s just a squared hole instead of a hole that respects the terrain mapping). Is there a way to “erase” a tile so that it uses the terrain system and automatically change the tiles around?
I’m afraid my question is unclear (sorry for my English, I’m French).

1 Like

Modulate: Sorry I didn’t explain that very well. It’s in the TileSet editor in the bottom panel, under the “Select” tab. There’s a picture of it in the docs for Assigning properties to multiple tiles at once.

The fastest workflow would be:

  • Create multiple TileSet Sources from the same texture, enough for one for each of the color variations you want.
  • Then use TileBitTools to assign the same template for each of them.
  • Then follow the instructions in the docs linked above: go to the “Select” tab, select all the terrain tiles in a Source, and click on the modulate color to change it for all of them at once.

Erasing terrain tiles: It’s similar to what you’re already doing with set_cell(), but you can use set_cells_terrain_connect(), and set the terrain parameter to -1. It should update the surrounding tiles.

Edited to add: For the set_cells_terrain_connect() function, if you have cells that match to empty space, make sure to set the parameter for ignore_empty_terrains to false. Then it will behave like it does in the editor.

However, if you’re doing it at runtime, some people have found it to be unreliable. It can be okay for some simple setups, but if you are noticing incorrect tiles placed even though your terrain sets are set up correctly, you might want to try the plugin Better Terrain.

And your question was very clear – your English is perfect! I hope this was helpful.

1 Like

Thanks for your answers! I managed to solve my problems thanks to your help.

I have a last question (sorry haha) regarding the way I’m supposed to change a tile color. Ideally, I would like to do it in code, and without having to use multiple tileset (for example I’d like to put some tiles in an array and color all of them, at runtime, by changing every tile’s modulation).
I found an old topic on the forum where they mention a method called tile_map.tile_set.tile_set_modulate(id, color): How to change tileset color using code - #2 by system

I searched on the documentation and it seems to be gone, but I searched in the tileset doc and also the tilemap doc (using ‘modulate’ keyword) and I have not found a new way to do that: changing a tile’s color in code at runtime. Which is weird because it seems to be possible in previous versions of Godot, but also because the Godot 4 tilemap’s documentation stipulates that “using set_layer_modulate() will be multiplied by tile’s color and TileMap’s modulate.”, so apparently there is a tile color (unless it means the color of the texture itself I guess).
The only think I found in this very page is the set_layer_modulate() function, but it seems to change the all layer modulate (the same way I managed to do it in the editor). I guess it’s ok and I could get away with it by creating multiple tileset sources, like you advised me to do, but I just wanted to be sure there currently is no way to change a single tile’s color/modulate.

Again, thanks for yor help! It solved all my problems, appreciate it a lot.

1 Like

Ah I think I understand a bit better what you’re trying to do.

I’m not familiar with the layer modulate options. But another way might be to assign a custom shader material to the tiles (next to where you set the tile modulate option), and then have a uniform variable in the shader you set via code that controls their color.

I haven’t done this specifically with TileMaps, though. Maybe someone else can chime in?

Correct me if I’m wrong but it seems that the same way you can’t choose a specific color for a tile, if you use a shader for the overall tilemap, I think its effects (like changing its color, for example) will be applied to all the tilesets…

I mean, worst case scenario I’ll have to create several tilesets of the same white tileset and just change their color individually, but it feels like it should be possible to do it by code and without having to duplicate tilesets… I could also use layers and change the modulation of each layer individually, but then it mean my layers will be organized in terms of color (which seems a bit weird, because usually you want to use layers to seperate different types of elements, stuff like that).

It’s not a single shader for the whole TileMap. You assign a material to specific tiles only in the TileSet editor’s Select tab.

Oh ok, I see. Thanks again for all your help!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.