Low fps with TilemapRenderer

Hello everyone,

I have a level generated using cellular automata.
My map is 1366/768 and each pixel is a tile (black or white).

This is the code i use in void Start() to display the map :

public void RenderMap(bool[,] map, Tilemap tilemap, TileBase tileNone, TileBase tileExist)
    {
        //Clear the map (ensures we dont overlap)
        tilemap.ClearAllTiles();
        //Loop through the width of the map
        for (int x = 0; x < map.GetLength(0); x++)
        {
            //Loop through the height of the map
            for (int y = 0; y < map.GetLength(1); y++)
            {
                // 1 = tile, 0 = no tile
                if (map[x, y] == false)
                {
                    tilemap.SetTile(new Vector3Int(x, y, 0), tileNone);
                }
                else if (map[x, y] == true)
                {
                    tilemap.SetTile(new Vector3Int(x, y, 0), tileExist);
                }
            }
        }
    }

I don’t know why but i have only 40 fps.
How can i improve that?

The final goal is to create a map where i can interact with each pixels (to create a destructible environment)

That’s a lot of tiles, over one million of them.

I’m surprised you’re even getting 40fps!!

I don’t think this approach will work.

You might have some luck with just showing a texture, then having some kind of optimized way of updating that texture as a result of the interactions.

Here was my lotto scratcher treatment:

I use a RenderTexture to update the visuals. Full code in comment links.

1 Like