Draw Tilemap patterns in code

I was wondering if I can draw a pattern in GODOT 4 at runtime,
through code, I am currently tring to use get_pattern and set_pattern and calling this function at _ready as you can see below.

However on runtime it doesnt show. Please let me know what Im doing wrong. Any help is apreciated! :smile:

TileMap.get_pattern() creates a new TileMapPattern from an array of cells from the TileMap

If what you want is to set patterns you already have in the TileSet then you’ll need to use TileSet.get_pattern() and then use that TileMapPattern in the TileMap.set_pattern() function.

For example:

	var pattern = tile_map.tile_set.get_pattern(0)
	tile_map.set_pattern(0, Vector2i(10, 10), pattern)

Thanks for the answer. Understood, however using it like this gives this error

The script is attached to a TileMap and extends TileMap, how can I reference the tilemap to correct this error?

That was an example, if you are using it in a script attached to a TileMap then drop the tile_map part.

That was the bit I was missing. Thank you all very much!!

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