Dynamic Mesh Collider - Optimization

So I’ve managed to create a mesh, alter its shape, and update its collision mesh every frame (right now its just a wave, but it works, it pushes cubes around).

My main thing now is that when the mesh gets too big, the updating slows down like crazy. The one line that slows the process is:

//Defined at start
private var meshCollide : MeshCollider; //later defined as the mesh collider 
                                        //on this object
private var clearMesh : Mesh; //stays empty
private var mainMesh : Mesh; //the mesh whose values I am adjusting

//Called in a "Update Mesh" function I have (called on each Update)
meshCollide.sharedMesh = clearMesh; //this line causes the delay, 
                                    //but allows the new mesh to be read properly

meshCollide.sharedMesh = mainMesh;

Is there a more efficient way of doing this?

EDIT: Well that was quickly resolved. I found that by using smaller “chunk” objects rather than one big one, the updating speed dramatically increased. Less memory operations, I would guess.

You could also try swapping

meshCollider.sharedMesh = clearMesh;

for

meshCollider.sharedMesh.Clear();

This may clear it more efficiently for you.