Change Z index (Tilemap) with Code

Godot Version

4,3

Question

I Make a simple platformer with Tiles. Now i had the idea that some decoration Tiles, should change random Z Layer. So that the Player walks sometimes Infront and sometimes behind the Grass Tiles.

I know you can grab tiles in the level, but can you select 1 Tile and randomes Z index (for example between 1-5) every time the Tile gets placed.

I hope you can at least understand what i mean haha

But i have no clue on how to make this.
Is this ever possible without tracking down every single Tile.

tile 1

I think you either have to set one specific tile-type to a fixed z layer (with the paint tool), which has the downside of it always being the same tile, unless you duplicate them. Or you have to use several tilemap layers

1 Like

That information is stored in the TileSet so you’ll need to create alternative tiles to have different rendering settings.

Another option is doing it at runtime using the TileMapLayer._tile_data_runtime_update() method and modifying the TileData.z_index property. Read the documentation to know how to use this method.

1 Like