- Home /
Tilemap Renderer problem generating random sprite Tiles
Hello, I`m trying to generate random tiles on a huge tilemap but changing the tile sprite seems to cause render problems. Also I have been playing a lot with the chunkSize, picking a small x value causes render problems and also picking a big y chunk size crashes unity. I`m currently using max size on x:512 and on y:1
This is a simple random sprite function I`m using :
void RandomTile()
{
if (Random.value < 0.5f)
{
selectedtile.sprite = grasstilesprite;
}
else
{
selectedtile.sprite = lumbertilesprite;
}
}
And this is my generation function :
Tilemap tilemap = GetComponent<Tilemap>();
TilemapRenderer tileren = GetComponent<TilemapRenderer>();
tileren.chunkSize = new Vector3Int(maxchunkx, maxchunky, 0);
for (int x = 0; x < xSize; x++)
{
for (int y = 0; y < ySize; y++)
{
RandomTile();
tilemap.SetTile(new Vector3Int(x, y, 0), selectedtile);
}
}
I have set Sort order to Top Right on Tilemap Renderer but it does not help when moving the camera around the sprites order overlap back and forth between the 2 sprites.
If I don`t mess around with the chunkSize Vector I get this every 32 positions (Default value for chunksSize Vector3Int is 32)
Does anyone know how can I start fixing this rendering problems? Or offer a better solution for generating tiles/tilemaps of huge sizes? Any help will be appreciated
Update : I found a temporary solution, creating different tilemaps one for each sprite type layer and setting their order. While setting a tile on one tilemap the others get set to null on the same position, I`m pretty happy with the result.