Hi, I am doing the following:
private Mesh mesh;
private void Awake()
{
var skin = GetComponent<SkinnedMeshRenderer>();
mesh = Instantiate(skin.sharedMesh) as Mesh;
// modifying mesh in some way...
skin.sharedMesh = mesh;
}
private void OnDestroy()
{
// Do I need to destroy the mesh or will Unity take care of it when the SkinnedMeshRenderer is destroyed?
Destroy(mesh);
}
I’ve seen some Unity editor crashes since writing this code and I am not sure if it’s a coincidence or if it’s because I am double-destroying the mesh. Do I need to destroy this mesh copy myself or will the SkinnedMeshRenderer do it for me?
Also, the “sharedMesh” property itself is confusing. I have multiple SkinnedMeshRenderers that are each being modified in this way, what is even being shared that justifies calling it a “sharedMesh”?