How do I clone a sharedMesh?

I have an editor script that clones an object and modifies the mesh of the clone. When I modify the sharedMesh, it changes not only the clone, but also the original. If I modify the mesh, the mesh collider does not change to match it.

How do I take the modified mesh, tell unity to define a new sharedMesh based on the modified mesh, and save it as a new prefab, probably using the AssetDatabase?

Hi, sorry for just pasting code, was a sloppy answer, the best way to do this is to clone the shared mesh, and to assign the clone, back to the sharedmesh property of the skinnedmeshrenderer…

myRenderer.sharedMesh = (Mesh) Instantiate( myRenderer.sharedMesh );

That way, the shared mesh is no longer an instance of the original.

Hope this helps!

It may be more straightforward to do something like this:

    var newMesh = new Mesh()
    {
           vertices = mesh.vertices, 
           triangles = mesh.triangles, 
           normals = mesh.normals, 
           tangents = mesh.tangents, 
           bounds = mesh.bounds,
           uv = mesh.uv
    };

so you’re essentially just copying over the details of the original mesh to a new Mesh instance.