- Home /
Serialize mesh in editor
I made slot machine prototype and generated the slot columns procedurally, setting parameters like the number of faces and images from my custom editor. I would like to know how to keep my gameobjects and their properties (values, components, meshes) when I press the play button. And when I stop the game, my values don't come back either. Any suggestions?
Answer by DavidDebnar · Jul 11, 2013 at 08:44 PM
You have two options here:
Use a plugin.
Save the mesh as an asset.
Plugin!
This seems, and probably even is, the simpler of these two. I can personally recommend WhyDoIDoIts Unity Serializer. It can preserve any changes made to variables at runtime.
Asset!
To create an asset at runtime, you'd use AssetDatabase.CreateAsset. It takes 2 parameters, an Object and a String.
function CreateAsset (mesh : Mesh, name : String) {
AssetDatabase.CreateAsset(mesh, "Assets/Meshes/"+name);
AssetDatabase.SaveAssets();
}
--David--
Well maybe I can use this for a new solution, but its not exactly what I'm looking for. I want objects in my scene (which were created by scripting) persist when I press the play button. I don't want to save and load them. Is this possible?
Oh, you should've said you're using C# ;) JS does that automatically, and I'm a heavy JS so I didn't even think of that.