I am using a modified version of a procedural generation asset which generates a mesh at runtime, but for performance i am trying to split the mesh into pieces.
Currently im dividing the arrays for the vertices, uv’s and triangles into 6 as thats how many pieces i want and then looping six times and each time copying the section from the arrays that i need and using it to make a mesh which would then be applied to a gameobject.
However when i run the code i get the following error:
“Failed setting triangles: Some indices are referencing out of bounds vertices.
UnityEngine.Mesh:set_Triangles(Int32)”
Any help resolving this issue would be greatly appreciated.
This is the code im currently using:
for (int i = 0; i < 6; i++)
{
//UnityEngine.Debug.Log("i is: "+i+" "+(i*vertsChunk));
Array.Copy(vectorArray, (i * vertsChunk), chunkverts, 0, vertsChunk);
Array.Copy(vectorArray2, (i * uvchunk), chunkUv, 0, uvchunk);
Array.Copy(vectorArray3, (i * uvchunk2), chunkUv2, 0, uvchunk2);
Array.Copy(numArray, (i*triChunk), chunktris, 0, triChunk);
Mesh m = new Mesh
{
vertices = chunkverts,
uv = chunkUv,
tangents = new Vector4[vertsChunk],
uv2 = chunkUv2,
triangles = chunktris
};
m.RecalculateNormals();
}