I’m trying to generate terrain dynamically in my game. While doing this I encountered the 65000 vertex limit, so in order to work around this I have made a prefab and just instantiated the amount of meshes I need in order to cover my terrain.
the mesh algorithm looks like this:
visualMesh = new Mesh();
visualMesh.vertices = verts.ToArray();
visualMesh.uv = uvs.ToArray();
visualMesh.triangles = tris.ToArray();
visualMesh.RecalculateBounds();
visualMesh.RecalculateNormals();
meshFilter.mesh = visualMesh;
meshCollider.sharedMesh = visualMesh;
In 95% of the cases this works perfectly but sometimes when i change the size of a triangle or make a small change in the procedure to add triangles to this mesh, approximately half of the mesh looses its collision detection and players and other objects just fall through the terrain. The annoying part is that i don’t know why. When i change the size of the triangles in one part of the mesh, the collision failure happens in an entirely different part of the mesh.