Saving a procedural object as a prefab/asset?

Hi,

I have written an importer to read a 3D model format that Unity does not support. I am able to load the model into the scene however I would like to then be able to save the model as a prefab, because the model is built procedurally created meshes/textures etc I can not do this. How can I save this gameobject and its children to a prefab structure for use in Unity?

This is what I am trying at the moment.

-Use AssetDatabase.CreateAsset on the root GameObject
-Use EditorUtility.CollectDeepHierarchy on the root
-Iterate through the found dependencies calling AssetDatabase.AddObjectToAsset on them.

I have found that this saves the structure however the Meshes, Materials and Textures are not being saved.
I found that I can add materials to the asset if I search for them however the Mesh object will not save for me if I do the same nor will the textures.

Can someone offer advice on how to save the Meshes and Textures(do I need to encode them to png?)
Should I use PrefabUtility.CreatePrefab instead?

Thanks

Karl

You’ll have to call CreateAsset on the individual mesh and material objects as well. The unity docs provide an example of how to actually save a material. I’ve personally saved mesh and material data this way but can only assume it’s the same for a texture. I’m betting your issue has more to do with how you’re enumerating the source model but without code couldn’t say.

have a look at this tutorial. use [Serializable] to make it storable by unity. no need to use the intermediate file formats imo.