Hello all. I’m making a block based building system for a mech fighting game but I seem to have hit a snag. You see I am trying to take all the blocks the player makes and assemble them into a single mesh to save memory, the problem is that when I try to draw this mesh I get an error that says “size <= 0”. That’s all it says, does not tell me what “size” is referring to. Although it does point to Graphics.DrawMeshNow as being the problem. Anyways, here is all the code relevant to the problem.
var VertexMasterArray = new Array();
var NormalMasterArray = new Array();
var TriangleMasterArray = new Array();
function Update(){
if (Input.GetKeyDown (KeyCode.V)) {
var BigMesh : Mesh = new Mesh();
var VBlocks = GameObject.FindGameObjectsWithTag("Block");
VertexMasterArray.Clear();
NormalMasterArray.Clear();
TriangleMasterArray.Clear();
BigMesh.Clear();
for (var i = 0; i < VBlocks.length; i++) {
var mesh : Mesh = VBlocks*.GetComponent(MeshFilter).mesh;*
-
var Vvertices : Vector3[] = mesh.vertices;*
-
for(var i2=0; i2<Vvertices.length;i2++){*
_ VertexMasterArray.Push(Vvertices[i2]+VBlocks*.transform.position);_
_ }_
_ }_
_ BigMesh.vertices = VertexMasterArray;*_
* for (i = 0; i < VBlocks.length; i++) {*
_ mesh = VBlocks*.GetComponent(MeshFilter).mesh;
var Vnormals : Vector3 = mesh.normals;
for(i2=0; i2<Vnormals.length;i2++){
NormalMasterArray.Push(Vnormals[i2]);
}
}
BigMesh.normals = NormalMasterArray;*_
* for (i = 0; i< VBlocks.length; i++) {*
_ mesh = VBlocks*.GetComponent(MeshFilter).mesh;
var VTriangles : int = mesh.triangles;
for(i2=0; i2<VTriangles.length;i2++){
TriangleMasterArray.Push(VTriangles[i2]+24i);
* }
}
BigMesh.triangles = TriangleMasterArray;*_
* BigMesh.RecalculateNormals();*
* BigMesh.RecalculateBounds();*
* BigMesh.Optimize();*
* VertexMasterArray.Clear();*
* VertexMasterArray = BigMesh.vertices;*
* NormalMasterArray.Clear();*
* NormalMasterArray = BigMesh.normals;*
* TriangleMasterArray.Clear();*
* TriangleMasterArray = BigMesh.triangles;*
* print(“Mesh Built”);*
* }*
* if (Input.GetKey(KeyCode.C)) {*
* var rotation = Quaternion.identity;*
* // Assign a rotation 30 degrees around the y axis*
* rotation.eulerAngles = Vector3(0, 0, 0);*
* var BigMesh2 : Mesh = new Mesh();*
* BigMesh2.vertices = VertexMasterArray;*
* BigMesh2.triangles = TriangleMasterArray;*
* BigMesh2.normals = NormalMasterArray;*
* BigMesh2.RecalculateNormals();*
* BigMesh2.RecalculateBounds();*
* BigMesh2.Optimize();*
* Graphics.DrawMeshNow(BigMesh2,Vector3(0,20,0),rotation);*
* }*
}
I’m pretty much at a loss as how to proceed next.