Displaying an objects MeshCollider

I have a deformed cube with a non-convex hull. I want to convert the deformed cube so its vertices lie in the same places but it has a convex hull.

I have MeshCollider attached to the deformed cube with Convex set to true and was hoping I could swap out the deformed cube’s Mesh with the mesh the MeshCollider uses for collisions- but Im having no luck.

I was hoping the MeshCollider’s Mesh was stored in the undocumented MeshCollider.mesh and so tried this:

var deformedMesh : Mesh = GetComponent(MeshFilter).mesh;
var collider : MeshCollider = GetComponent(MeshCollider);
var colliderMesh : Mesh = GetComponent(MeshCollider).mesh;

collider.convex = true; //set the MeshCollider up
collider.sharedMesh = null; //the deformed mesh gets re-deformed every now and then
collider.sharedMesh = deformedMesh; 

deformedMesh = colliderMesh; //replace the cubes mesh with a convex version of itself?

//alsotried

deformedMesh.vertices = colliderMesh.vertices;
deformedMesh.triangles = colliderMesh.triangles;
deformedMesh.normals = colliderMesh.normals;

But it seems that the MeshColliders Mesh is not stored in MeshCollider.mesh as the above code does nothing- does anyone know of a way of accessing the mesh the MeshCollider uses for collisions?

Thanks

The mesh is referenced in the (documented) MeshCollider.sharedMesh. MeshCollider.mesh is the instance; works the same way as Renderer.material and Renderer.sharedMaterial. But assigning colliderMesh to deformedMesh will not make a copy, if that’s what you’re trying to do; that’s just a reference, which makes deformedMesh and colliderMesh point to the same thing.

–Eric

I thought that may be the case but thanks for clarifying it.

I’ve since found a workaround by altering the convex hull generation found at
http://scrawkblog.com/2014/06/16/delaunay-triangulation-in-unity/

I’ll post the code when I’ve had a chance to tidy it up.