What is the binary data format of a TileMapLayer?

Godot Version

Godot 4.6.1

Question

I need to convert a TileMapLayer to an array of plain integers representing the tile indexes, eg. [0, 1, 2, …]. This needs to be quickly done at runtime so I would prefer to process the raw tile data instead of calling a method on each tile. I know TileMapLayer.tile_map_data contains the raw data of the map, but what is the format of this byte array?

For instance, if I have a map with a single atlas source and I place tiles 0, 1, 2 in the upper-left corner I get out the byte array [0, 0, 0, 0, 13, 0, 0, 0, 1, 0, 0, 0, 0 …]. I would assume the map is a bunch of 32-bit unsigned little endian integers but it seems like a lot more is stored there…

Why do you need this?

Well, if you want to know all the details it would probably be best to simply look inside the engine source code.

Never mind. I just joined the discord and got my answer there. It’s an array of 12-byte structures which each contain the 16-bit values:

[x][y][source_id][atlas_coords_x][atlas_coords_y][alternative_tile]

Relevant code