- Home /
Why do changes to a mesh persist until I restart Unity
When I modify a mesh from a C# script during play, the changes remain visible even after I hit stop. That would be OK, except that after re-starting Unity, all the changes are gone.
Further to that, if I have multiple copies of an object in the scene (copies of Unity's primitives or copies of my own imported model) the edits I make to one copy appear on all copies. As stated above, the edits persist after I stop play but disappear when I restart Unity. The only way I can have the edits not appear on all copies of an object is to have unique source models (I.E. obj files) in the file system. Using separate prefabs (made from the original object) doesn't solve this either.
Is there a way to refresh the models, similar to what restarting Unity does?
Is there a way to have unique models (but identical copies) in a scene without having multiple source obj files in the filesystem?
Can you not make a new mesh equal to the old mesh and whack it in to the renderer?
Answer by zach-r-d · Jul 30, 2015 at 07:39 PM
This is happening because the script is editing the actual mesh asset itself rather than a copy of it.
If the mesh is being accessed via MeshFilter.sharedMesh, consider using MeshFilter.mesh instead. If the mesh is being assigned directly to a public field, then the script should Instantiate() a new copy of the mesh (perhaps in Awake() or Start()) before editing it.
Your answer
Follow this Question
Related Questions
Can't generate 3D meshes via script 1 Answer
Applying texture to all meshparts 1 Answer
Does mesh.triangles also return a copy of the triangle array? 1 Answer
Multiple materials on one mesh 1 Answer
TextMesh/3DText modify shape 0 Answers