In the game that I am making, a common task is to create new meshes to add to a pre-determined object. (The code for how I am currently doing this is included at the bottom of this post).
I create meshes by calculating the vertexes at 8 points on in the game, and generating a new temporary object mesh between those points (Parallelogram), then I create a new temporary empty gameObject, combine the master mesh with the temporary mesh in that object, then finally save the new temporary mesh back into the master mesh.
Obviously this is an extremely memory process, and when I test the game my FPS averages between 250 and 300, which drops to 25 while making objects (1 per frame, yes it is necessary), then immediately returns to its previous higher number when I stop creating. My question is: is there a more optimized process for creating meshes and adding them to an object?
//temp1 is the First Temporary Mesh (in which I set vertices), temp2 is the second, and Master is the gameObject I am attatching them to.
var meshFilters = temp1.GetComponent(MeshFilter);
var combine : CombineInstance[] = new CombineInstance[2];
combine[0].mesh = meshFilters.sharedMesh;
combine[0].transform = meshFilters.transform.localToWorldMatrix;
var meshFilters2 = GameObject.Find("Master").GetComponent(MeshFilter);
combine[1].mesh = meshFilters2.sharedMesh;
combine[1].transform = meshFilters2.transform.localToWorldMatrix;
var temp2 : Mesh = new Mesh();
temp2.CombineMeshes(combine, true, true);
GameObject.Find("Master").GetComponent(MeshFilter).mesh = temp2;
GameObject.Find("Master").GetComponent(MeshFilter).mesh.RecalculateNormals();
GameObject.Find("Master").GetComponent(MeshFilter).mesh.RecalculateBounds();
GameObject.Find("Master").GetComponent(MeshFilter).mesh.Optimize();
GameObject.Find("Master").GetComponent(MeshCollider).mesh = GameObject.Find("Master").GetComponent(MeshFilter).mesh;
Destroy(temp1);
Thank you all very much for tolerating my wordiness. I just thought more information would be better than less.