I create mesh dynamically like this from other mesh in editor (not play mode).
Mesh newMesh = Mesh.Instantiate(mesh);
I’m using this mesh on SkinnedMeshRenderer.
In skinned mesh renderer mesh appears and it’s name is postfixed with “(Cloned)”.
What I don’t understand is how this mesh survives editor restart, how is it saved and why ?
When I restart the editor this mesh is still on a scene and SkinnedMeshRenderer is referencing it, there is no asset, and this mesh have no asset path.
It’s saved as part of whatever scene asset or prefab asset it’s part of I’d imagine. Make such a change then check your VCS diff to see the scene file changes.
I don’t think they’re saved as part of a prefab (creating and setting a mesh inside of prefab yields an invalid reference), but maybe they’re saved on the scene?
I do hope that they’re discarded because otherwise the scene would become completely cluttered by repeatedly generating meshes?
Like any Unity object you just need to destroy it when no longer required. So if you have a generated mesh and need to replace it, either destroy the inital object and instance a new one, or write over the verts, normals, etc of the existing asset.
Mesh’s do seem to be weird in that you can serialise them into a scene, I’ve noticed, without having to write them as an asset to project files. Dunno if any other Unity objects, such as Texture’s are like this. Scriptable Objects don’t seem to work this way.