I have scene with 70*70 Cubes, and when i start the game, Unity write this message to Console and game is crashed. I want to make a bigger scene like in MineCraft Game. Thousand cubes in one scene. How i can do this?
As far as I can tell, Unity is trying to batch all the cubes into a single mesh, which is why you're hitting the vertex limit. This certainly seems like a bug as I'd expect Unity to group them into multiple batches once the limit is exceeded. You can find details on Unity's batching here: Draw Call Batching
However, spawning a game object per cube probably isn't the best way to approach this problem. You would be better off combining them into a single mesh manually using Mesh.CombineMeshes(). For example:
var cubes : GameObject;
var filter : MeshFilter;
var cubeMesh : Mesh;
function Start() {
cubes = GameObject.CreatePrimitive(PrimitiveType.Cube);
filter = cubes.GetComponent(MeshFilter);
cubeMesh = filter.mesh;
filter.mesh = new Mesh();
GenerateMesh();
}
function GenerateMesh() {
var instances : CombineInstance[] = new CombineInstance[70 * 70];
for (var i = 0; i < 70 * 70; i++) {
instances*.mesh = cubeMesh;*
_instances*.transform = Matrix4x4.TRS(*_
<em>_Random.insideUnitSphere * 5,_</em>
_*Quaternion.identity,*_
_*Vector3.one*_
_*);*_
_*}*_
_*filter.mesh.CombineMeshes(instances);*_
_*}*_
_*```*_
_*<p>4,900 cubes puts you at 117,600 vertices so you'll need to partition the cubes into multiple meshes to ensure you stay within the 65k vertex limit. Anything over that doesn't get rendered.</p>*_
_*<p>Another option would be to write your own mesh generation routine, the advantage there being that you can avoid the creation of superfluous faces that are hidden by other cubes.</p>*_
As you've found, Unity has a maximum vertex limit of 65536.
You'll have to divide your areas of cubes into separate meshes, so that each mesh does not exceed this limit.
I create cubes with this code :
function Start ()
{
var cube : GameObject;
for (var i=0; i<70*70; i++) {
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = Random.insideUnitSphere * 5;
}
}
As you see all mesh is separete.
It seems this problem was introduced in Unity 3. I am working on something similar and I did not get this error until I updated.
To get around it you can try to combine the cube meshes:
var parents : Array;
var grandParent : GameObject;
function Start () {
grandParent = new GameObject();
parents = Array();
var currentParent : GameObject;
var cube : GameObject;
for (var i=0; i<70*70; i++) {
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = Random.insideUnitSphere * 30;
if (i%100==0) {
currentParent = new GameObject();
parents.Push(currentParent);
currentParent.transform.parent = grandParent.transform;
currentParent.AddComponent(CombineChildren);
}
cube.name = "cube" + i;
cube.transform.parent = currentParent.transform;
}
}
No, this bug does not depend on the positions of blocks...