Hi!
I’m curious, how to save a procedural (script generated) mesh as an asset. I was trying to do it, I failed.
What I tried is:
get the Mesh Filter component’s mesh, store it in a variable and use AssetDatabase.CreateAsset.
I wanted to do it with a custom GUI. There is a button and a textfield. I can name the asset with it. It puts the mesh to Assets/CustomModels/. It makes the asset based on the first selection (Selection.transforms[0]).
When I press the Save Mesh button (I called as that), it makes the asset first time, but after that, it doesn’t work.
I guess it can’t overwrite the asset, but it even don’t work if I give it a new name.
Here is the error I get always:
Couldn’t create asset file because the
Mesh ‘NewPlain’ is already an asset at
‘Assets/CustomModels/NewPlain.asset’!
UnityEditor.AssetDatabase:CreateAsset(Object,
String) SaveMeshAsset:OnGUI() (at
Assets/Editor/SaveMeshAsset.js:28)
UnityEditor.DockArea:OnGUI()UnityException: Creating asset at path
Assets/CustomModels/NewPlain2.asset
failed. SaveMeshAsset.OnGUI () (at
Assets/Editor/SaveMeshAsset.js:28)
System.Reflection.MonoMethod.Invoke
(System.Object obj, BindingFlags
invokeAttr, System.Reflection.Binder
binder, System.Object parameters,
System.Globalization.CultureInfo
culture)
I’m a very beginner script writer, and I don’t get the reason of the error. The script first changes the nameOfMesh variable that is modifiable from the GUI.TextField, and after it had to save.
There are several places you could get things wrong. Maybe this video will help: [Unity Tips and Tricks][1] [1]: http://www.youtube.com/watch?v=3jHe1FzrKD8
– insominx