Is there a way to create TileMapPattern from code and add it to the patterns of the TileMap?

Godot Version



I want to store the patterns created by procedural content generation algorithms in the patterns of my TileMap via code so they appear in the dock window below.

Is there a way to add a new TileMapPattern to the patterns of the TileMap?
I can’t find a method for it, but maybe there’s a workaround.

If there’s no way to do this, is this feature planned for the near future?

var tile_map_pattern_size := Vector2i(16, 16)
var tile_map_pattern :=
for used_cell in get_used_cells(0):
	if used_cell.x > map_position.x + tile_map_pattern_size.x or used_cell.y > map_position.y + tile_map_pattern_size.y:
	var atlas_coords := get_cell_atlas_coords(0, used_cell)
	tile_map_pattern.set_cell(used_cell, 0, atlas_coords)
## works as expected
var atlas_coords := []
for used_cell in tile_map_pattern.get_used_cells():
# add the tile_map_pattern to the patterns of this tilemap somehow... 

You’re looking at TileMap, but the patterns are stored in TileSet.

Just add_pattern() on the TileSet instance to store it and it should show on the dock.

1 Like

Thank you! When I add this line though, the editor crashes… (I’m using a @tool script btw.


Then you gotta file a bug report on the github 'cause that seems like it should just work.

Make sure to include the least amount of files that still cause the bug in your project with the bug report. That will help pinpoint the issue. Some threading race condition is my guess.