- Home /
What is the best way to return a deformed mesh to its initial shape?
I've been toying around with mesh deformation lately, but I've noticed that the mesh seems to save it's state between session - in order to make it return to its original shape I have to close out of Unity entirely. Is there any convenient way to force the mesh back to its original shape when the session ends? (Or at any point, for that matter). At the moment, my only thought is to store the initial positions of every vertex, and then restore those positions when I'm done, but I'm not entirely sure how to detect the end of the test session (when I "unclick" the play button in Unity), and feel like there ought to be a more elegant solution.
A simple solution is just copy it when you are "beginning work". Use only the copy.
This can avoid the tremendous confusion of what the hell "shared$$anonymous$$esh" means, etc :)
Answer by syclamoth · Sep 17, 2013 at 06:25 AM
This... really shouldn't be happening. Make sure you instantiate the mesh at the beginning of the session, and edit that- otherwise you are editing the imported base mesh, which you probably don't want to do. Either way, you can simply use 'OnApplicationQuit' to detect when the session ends, but as you say that's not very elegant.
Actually most direct changes to Assets will persist, even when changed at runtime. Only stuff placed in a scene is reverted because that is serialized / deserialized. The imported $$anonymous$$esh data is stored in the library folder. It's only loaded when you start Unity / your game. All changes you made will persist until you restart the application. The changes might even persist a restart once Unity has invalidated the asset and store it back to disk.
If the mesh was an imported FBX, the FBX isn't changed, but the imported $$anonymous$$esh. You can reimport the FBX asset at any time to revert any changes to the imported mesh. At runtime the only way is to restart the application.
yup, this is the "normal, annoying, confuising at first" behaviour!
Ah! Thank you very much, used this and Fattie's comment - now I'm creating a copy of the mesh in Start(), and only making changes to that. Thanks, both of you!
Your answer
Follow this Question
Related Questions
Unassigned Reference Exception 4 Answers
Animated Texture Offset 1 Answer
adding animation dynamically by script 0 Answers
Playing an animation with C#? 1 Answer