Alrighty I found this package, How to use Unity’s memory profiling tools | Unity, which is pretty darn cool. You can go in and view every single memory allocation you do.
I found out that one of my chunks is only 3MB but the problem was where I was building and combing the mesh faces. Here is an example of how I was building and combing the mesh faces for each block.
Mesh m1 = new Mesh();
Vector3[] v1 = new Vector3[4];
v1[0] = new Vector3( 0.5f, 0.25f, -0.5f);
v1[1] = new Vector3( -0.5f, 0.25f, -0.5f);
v1[2] = new Vector3( -0.5f, 0.25f, 0.5f);
v1[3] = new Vector3( 0.5f, 0.25f, 0.5f);
m1.vertices = v1;
m1.triangles = new int[6] { 0,1,2,0,2,3 };
Vector3[] uvs1 = new Vector3[] { new(0,0,1), new(0,1,1), new(1,1,1), new(1,0,1) };
m1.SetUVs(0, uvs1); geometry.Add(m1);
Mesh m2 = new Mesh();
Vector3[] v2 = new Vector3[4];
v2[0] = new Vector3( 0.5f, -0.25f, -0.5f);
v2[1] = new Vector3( -0.5f, -0.25f, -0.5f);
v2[2] = new Vector3( -0.5f, -0.25f, 0.5f);
v2[3] = new Vector3( 0.5f, -0.25f, 0.5f);
m2.vertices = v2;
m2.triangles = new int[6] { 2,1,0,3,2,0 };
Vector3[] uvs2 = new Vector3[] { new(0,0,0), new(0,1,0), new(1,1,0), new(1,0,0) };
m2.SetUVs(0, uvs2); geometry.Add(m2);
CombineInstance[] combiner = new CombineInstance[geometry.Count];
for(int i = 0; i < geometry.Count; i++) {
combiner[i].mesh = geometry[i];
combiner[i].transform = Matrix4x4.TRS(new Vector3(x, y * 0.5f, z), section.transform.rotation, section.transform.localScale);
}
m1.name = "Full1";
m2.name = "Full2";
Mesh c = new Mesh();
c.CombineMeshes(combiner, true, true);
c.name = "CombinedFull";
section.opaque.Add(new(x,y,z), c);
I was building each face and then using the unity “CombineMeshes” method to pack them all together for the chunk but I needed to make sure to destroy the temporary faces I was building like so.
GameObject.Destroy(m1);
GameObject.Destroy(m2);
Oh and if you want an asset to show up in the memory profiler you can give it a name like so.
m1.name = "Full1";
m2.name = "Full2";
So you can pinpoint where the problems are.