AnimatedTexture created in code won't animate in TileMap

Godot Version

v4.2.1.stable.official [b09f793f5]


I am trying to create an AnimatedTexture tile in my TileMap. My render frame function does palette cycling to render new animated Images, here’s my function:

func render_animated_frame(
		frame_index: int,
		animation_count: int,
		palette_index: int=0) -> AnimatedTexture:
	var animated_frame_texture :=
	animated_frame_texture.frames = animation_count
	for i in range(animation_count):
			i, ImageTexture.create_from_image(
		animated_frame_texture.set_frame_duration(i, 0.5)

	return animated_frame_texture

Here is how I build my TileSetSources (all TileSetAtlasSources):

	for i in range(len(tiles)):
		var tile_index := tiles[i].ab_index
		var palette_index = tile_renderer.tbl.palette_indices[tile_index]
		var image_key := String.num(tile_index) + "-" + String.num(palette_index)
		if image_key not in tile_renderer.images:
			var frame := tile_renderer.get_frame(tile_index)
			var palette := tile_renderer.pal.get_palette(palette_index)
			var tile_texture: Texture2D = null
			if palette.is_animated and \
				tile_texture = tile_renderer.render_animated_frame(
					len(palette.animation_indices) / len(palette.animation_ranges),
				tile_texture = ImageTexture.create_from_image(
			var tile_set_source :=
			tile_set_source.texture = tile_texture
			tile_set_source.texture_region_size = Resources.tile_size_vector
			tile_set_source.create_tile(Vector2i(0, 0))
			tile_set.add_source(tile_set_source, tile_index)

To debug, I looped over my AnimatedTexture’s frames and saved each frame as a PNG… Manually making a GIF, this is what my animated water tile should look like (it’s subtle, sorry):

The animated tiles render along side non-animated tiles, but it’s like they’re not “playing” or stuck on frame 0? I’m stumped on what else to try, the AnimatedTexture has the frames in resource itself, but it seems like the TileMap doesn’t want to animate the tile.

Any suggestions to try? Thanks for the help in advance!


Don’t use AnimatedTexture It’s deprecated and its current implementation is not efficient.

You can still create tile animations. The animation tiles need to be together in the same texture. Here’s a small tutorial to do it from the editor How to create an animated tile in Godot 4's tilemaps | To do it from code you can use all the TileSetAtlasSource.set_tile_animation_*() functions.

Either way, the TileSetAtlasSource.use_texture_padding property will generate an internal texture and won’t respect the AnimatedTexture animation.

1 Like

This worked, thanks! Here’s a GIF of the water moving:

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