Hi,
I am generating voxel terrain that consists of many different individual chunks. I am doing this in a UnityJob, so it runs smoothly without any stuttering.
However, after the UnityJob is finished and I create the mesh, I experience a frame drop.
So far, I haven’t found a way to do this without stuttering. I thought about doing this in a coroutine and distributing the mesh creation over multiple frames.
But I only know how to create the mesh all at once with all the data at once:
NativeArray<Vector3> verticesArray = chunkJob.Vertices.AsArray();
NativeArray<int> trianglesArray = chunkJob.Triangles.AsArray();
NativeArray<Vector2> uvsArray = chunkJob.UVs.AsArray();
Mesh mesh = new Mesh();
mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
mesh.SetVertices(verticesArray);
mesh.SetTriangles(trianglesArray.ToArray(), 0);
mesh.SetUVs(0, uvsArray);
mesh.RecalculateNormals();
mesh.RecalculateBounds();
meshFilter.mesh = mesh;
meshCollider.sharedMesh = mesh;
Does anyone know how I can distribute this over multiple frames?
Thanks and have a nice day