- Home /
Save mesh generated in game to editor.
I followed this tutorial: https://unity3d.com/learn/tutorials/projects/procedural-cave-generation-tutorial
Every thing worked fine but I want to save the generated cave to the editor.
The finished project is here: https://github.com/SebLague/Procedural-Cave-Generation
I tried pressing play then coping and pasting the cave from play to the editor but the mesh unsets :(
You could try to use EditorUtility.SetDirty, if that doesn't work then you'd have to write and read the data to and from a file, for example with Serialization and a BinaryFormatter. Edit: You can also use Editor Extensions to generate your mesh while in Editor mode; The generated mesh will stay then.
Answer by alishka · Jan 16, 2016 at 07:24 PM
I don't know how exactly do you want to "save it to editor", because for reading/displaying raster mesh data, the model has to be saved in a specific format which the engine understands (FBX, OBJ, etc.)
So, say you have generated your cave, I'm assuming you're keeping your mesh data somewhere (I'll read the code on github later). With that mesh data, you can use ExportOBJ, that will let you save your procedurally generated cave (GameObject) into a .OBJ file that will be saved to your project directory for later use. No need to build an exporter from scratch as @Cherno suggested.
Nice work on the cave generator!
Cheers!
Thanks, I ended up changing the script to run in the editor.
Answer by lassade · Jan 17, 2016 at 05:43 AM
If you just want to use it inside the editor you can place ExecuteInEditMode attribute in your cave generator script. You can change the hideflagd of your mesh as well ( if you dont want to keep it, since you always will generate a new one ! ).
Inside the editor as well using an editor script you can simple save the mesh by calling http://docs.unity3d.com/ScriptReference/AssetDatabase.CreateAsset.html, the mesh saved will have a .asset extension and you only can use it inside unity.
Correct if i'm wrong but you want to save the mesh because you cant see it while in editor mode and then you cant create your level from that. If is the case give a look in the how to build editor scripts this way you will be able to create a cave and build a level from that really easy. This is just suggestion you dont really need to.