- Home /
500K upper bound on total number of meshes?
I'm creating a procedural terrain system that bypasses the normal Unity object system. I work directly with meshes and render them by calling Render.DrawMesh.
The terrain is organized into tiles. Because the player can edit individual cells within a tile, I assign each cell its own mesh. When a cell is edited, I update the mesh for that cell, then call CombineMeshes to rebuild the big mesh for the entire tile.
This of course means I have A LOT of tiny cell meshes. As I started scaling up my map I discovered that past a certain point the game would hang on initialization. I've tracked it down to the code that allocates the meshes for the cells. It looks like there's an arbitrary hard limit of 500K for the total number of meshes in a Unity game.
I don't expect this will be fixed since most people aren't using Unity in the strange way that I am. However, it would be nice if:
There was official confirmation that this limit does exist.
This limit was documented somewhere.
Unity would crash with an error when this limit is reached instead of hanging.
Here's a little code snippet. Below 500K the allocation of meshes works fine. Above 500K it hangs:
Mesh[] meshTest = new Mesh[525000]; for (int i = 0; i < meshTest.Length; i++) { meshTest[i] = new Mesh(); };
(Note -- This has nothing to do with the 64K limit on vertices within a mesh.)