Your RAM is your limit.
The following tests were performed on a system with these specs:
- Intel i5-6600
- 16 GB RAM
- NVIDIA GeForce GTX 1070
- Windows 7 Home Premium
Here is a script I ran which grows a tilemap by filling it with a single tile (32x32 pixels). The Method Grow()
adds another column and another row to the current map. The method gets called 100 times each update.
public class TileTest : MonoBehaviour {
public Tile tile;
private Tilemap tilemap;
public int currentSize;
void Start () {
tilemap = GetComponent<Tilemap>;
Grow();
}
void Update() {
for (var i = 0; i < 100; i++) {
Grow();
}
Debug.Log(currentSize);
}
private void Grow() {
for (int x = 0; x < currentSize; x++) {
tilemap.SetTile(new Vector3Int(x, currentSize, 0), tile);
}
for (int y = 0; y < currentSize; y++) {
tilemap.SetTile(new Vector3Int(currentSize, y, 0), tile);
}
tilemap.SetTile(new Vector3Int(currentSize, currentSize, 0), tile);
currentSize++;
}
}
After a few minutes, my computer ran out of memory and Unity crashed. At that point it was at 8400x8400 (70 million) tiles and Unity.exe was consuming slightly above 11 GB of RAM according to the task manager.
Well, but what about sparse maps?
Here is a different script which placed a single tile at increasing x and y coordinates in increments of 100 tiles:
public class TileTest : MonoBehaviour {
public Tile tile;
private Tilemap tilemap;
public int currentSize;
void Start () {
tilemap = GetComponent<Tilemap>();
}
void Update() {
tilemap.SetTile(new Vector3Int(currentSize, currentSize, 0), tile);
currentSize+= 100;
}
}
The memory footprint of Unity.exe in fact increased very little, which hints that empty tileset cells require almost no RAM. However, the FPS kept falling as the tileset was growing. It hit 60 Fps at 30000x30000, 30 Fps at 60000x60000 and 15 Fps at 90000x90000. The Fps stayed that low when I removed the script while the test-game was running. So this slowdown was not from changing the tilemap. It was simply from rendering it. So when you want to create a really huge open world game, you might have to use multiple smaller tilemaps which you create and destroy at runtime.
Conclusions: Huge but mostly empty tilemaps do not use much RAM, but they are a rendering bottleneck, even when most of it is not in the camera viewport.
I then experimented with this script which generates tilemaps with a given size:
public class TileTest : MonoBehaviour {
public Tile tile;
public int xSize;
public int ySize;
void Start () {
Tilemap tilemap = GetComponent<Tilemap>();
for (int x = 0; x < xSize; x++) {
for (int y = 0; y < ySize; y++) {
tilemap.SetTile(new Vector3Int(x, y, 0), tile);
}
}
}
}
I used this script to generate a 8192x8192 map. It took a few minutes, but when the script was finished, it ran at steady 95 Fps.
Conclusion: Maps with millions of tiles are feasible, at least on gaming PCs.