- Home /
Creating a Mesh asset inside the editor
I am trying to save a generated Mesh from an imported .obj file. I basically take a sphere which I have created and UV mapped in blender and then modify it. This works fine, I get exactly the result I want, now I want to save out this new mesh as an Asset, which is where I have trouble.
When I try to save the Mesh using AssetDatabase.CreateAsset, i can see an object in the Project panel but it has no type, inside explorer I can see that it's a 64kb file. Do I need to add a file extension?
When I look at the Meshes I have imported they seem to be multiple objects is this necessary or is it possible to save a single Mesh asset by itself?
I have tried using the objexporter script from the Unify wiki but the UVs get ruined in the process.
Any help would be greatly appreciated.
Answer by Jessy · Jun 21, 2012 at 10:15 PM
.asset
You must ensure that the path uses a supported extension ('.mat' for materials, '.cubemap' for cubemaps, '.GUISkin' for skins, '.anim' for animations and '.asset' for arbitrary other assets.)
What would I do without you Jessy?! I'll try this when I get home. Thank you so much.
*Edit - Docs have moved, but still state the same thing. $$anonymous$$e == dumb.
http://docs.unity3d.com/ScriptReference/AssetDatabase.CreateAsset.html
BTW I don't feel like this is a very good answer. That page just contains a partial list of asset extensions and states "'.asset' for arbitrary other assets". If that's the only information you're using then you're effectively resolving the "case not implemented" error by adding an empty default and calling it a day without even looking at the code involved. This happens to be correct in this case, just like a broken clock, but it is quite misleading... (that's more on the Docs than your answer though).
Thanks for the updated link, Sleazy. When linking to an answer, it is always best to include the gist of the answer as well, or else a Google phrase that is likely to find it again when its URL changes.
You're right. I've fixed the documentation link in the answer and added a quote of the essential part :)
I'd like to add (because S$$anonymous$$zy seems to be somewhat upset by the docs) that the ".asset" extension can be used for any kind of asset, even materials, GUISkins, ... Unity's asset format is kind of "universal". You can also pack multiple assets into one asset file. See AssetDatabase.AddObjectToAsset
Hey, thanks for doing that. Just to round it all out: I've been using the .mesh extension explicitly and it works fine in 2018.4.