- Home /
Export/Save procedural GameObjects with meshes
Hi all,
I'm new to unity (first post) and I apologize in advance if there is an obvious answer to this question, but I promise I've been looking for a solution for ages now and haven't found one.
I have a unity project that generates gameobjects with meshes during runtime. This obviously means that my gameobjects are removed from the scene as soon as I hit stop. I want to export these gameobjects (or the whole scene including these) so I can reuse them in another unity project so that the generation process won't be needed next time. The problem is, that I want to export all components and dependencies of the gameobjects.
What I tried:
Save the scene via File -> Save scene. Problem: as you know, you can't save a scene whilst in play mode and all the changes made in play mode will be discarded on stop.
Make prefabs from the generated gameobjects. Problem: the meshes aren't being attached to the prefabs.
Export the objects via Assets -> Export Package... . Problem: this doesn't save any of the generated gameobjects.
Use the EditorObjExporter.cs script from http://wiki.unity3d.com/index.php?title=ObjExporter . Problem: this only exports the meshes without the other gameobject components.
Create an editor script that saves selected gameobjects to an asset and then exports them into a package. Problem: importing the package in a new project results in gameobjects which are missing basically all the information from the original gameobjects except maybe the name.
What I think could work but haven't tried so far, since I very much hope there is a simpler solution:
Save the procedural gameobjects with the help of assetbundles. However, that seems overly complicated to me, since I only want a local copy of the gameobjects and don't need any streaming functionality.
Save the gameobjects as prefabs and separately save the meshes and somehow put both back together in the new project via scripts.
Thanks in advance for your help :)
You have to save the meshes as an asset - no choice over that I'm afraid. I'm pretty sure that you can fix it so the mesh is added to the prefab though. You would need to use the AssetDatabase functions to do this...
I signed in just to upvote the question. Besides the fact that it's exactly the same thing I want to do, it's clearly written, explaining what you're doing and why, with excellent "here's what I tried/here's what happened" support. Pure Gold.
Answer by Schnodahipfe · Apr 15, 2013 at 12:20 PM
I finally found this great plugin, which can save the gameobjects with all its components: http://whydoidoit.com/unityserializer/
sorry that nobody told you this more quickly - it's like the single most famous plugin for Unity - everyone uses it
no worries, it was my lack of expertise that prevented me from finding it because I didn't consider using "serialization" as a search phrase ins$$anonymous$$d of "save" and "export"
at whydoidoit: I just realized that it was you who commented on my post ;) - great tool!
Thanks! Yeah I obviously missed that you want this at runtime :) $$anonymous$$y comment was about creating a mesh inside a prefab (probably because I was doing that just recently).
Does it allows you to save individual prefabs? I want to generate "levelsections" save those individually as prefab and load these prefabs to make copies while the game is really running and not the editor?
Answer by yusufsermet · Feb 01, 2017 at 09:07 AM
Hi All,
Thanks @Schnodahipfe for the great description of the problem. After 4 years of the original question, I am facing with the same problem. I tried the updated version of the Unity Serializer (link here), however it does not save the scene in an independent file.
What I want to do is to generate a scene (3d maps) in a Unity project, then, I want to load the generated scene from another Unity Project. Is this possible? Any help and leads are extremely appreciated. I have been working on this for quite some time.
Note: Using the updated version of the Unity Serializer, I was able to save and load the scene in the same Unity Project, however, I couldn't make it work in a different project.
Thank you.
@yusufsermet Hi, I have the same problem. Do you find someway to solve this issue? save Gameobject in the runtime not editor. If you had solved this issue ,please tell me . Thank you
Answer by RyanShackelford · Apr 25, 2018 at 11:36 PM
You can save generated meshes as .asset and .prefab files using AssetDatabase and PrefabUtility.
For Assets: https://docs.unity3d.com/ScriptReference/AssetDatabase.CreateAsset.html AssetDatabase.CreateAsset(mesh,"Assets/" + "assetName.asset"); AssetDatabase.SaveAssets();
For Prefabs: https://docs.unity3d.com/ScriptReference/PrefabUtility.html PrefabUtility.CreatePrefab("Assets/Prefabs/saveMeshAsPrefab.prefab", meshGameObject);
Your answer
Follow this Question
Related Questions
Programmatically Exporting an Asset Package 4 Answers
How to save changes of fbx subassets ? 0 Answers
How to export objects that are part of a single imported FBX file 1 Answer
Maya LT - Export group as single FBX 0 Answers
Unable to save the mesh when RecalculateNormals() is applied to the mesh in the editor script 1 Answer