- Home /
HowTo create a mesh asset from editor ?
Greetings all,
I am about to make an editor which will create a dynamic mesh, and the only part I don't know how to take care of is the part that turns the mesh into an asset and used it as a shared mesh. I can handle dynamic meshes just fine, but it would be a big help to 'save' it as an asset
Would appreciate the missing link
Answer by Jessy · Apr 25, 2011 at 05:04 PM
Simplest possible case I can think of:
using UnityEngine; using UnityEditor;
class ProceduralMesh {
[MenuItem("Assets/Create Procedural Mesh")] static void Create () {
string filePath = EditorUtility.SaveFilePanelInProject("Save Procedural Mesh", "Procedural Mesh", "asset", ""); if (filePath == "") return; AssetDatabase.CreateAsset(new Mesh(), filePath);
}
}
Whatever you do, don't change the mesh compression value on that (the only available setting for the asset, in the Project view). It will destroy the data stored in the mesh, and you'll have to create it again. I reported this bug last summer, but nobody's fixed it yet.
Answer by Bryan 4 · Apr 25, 2011 at 04:52 PM
You may want to look into the AssetDatabase class. http://unity3d.com/support/documentation/ScriptReference/AssetDatabase.html
it is the answer. He did not ask for a script example, he presented himself as a competent programmer and can figure it out himself with the correct guidance of the resource which he wanted.
Hah. Yes. I was trying to figure out what part of the "green" answer was the actual answer when I remembered I had a scroll on my mouse :-)
Your answer
Follow this Question
Related Questions
[Solved]Why doesn't my ScriptableObject based asset save using a custom inspector ? 1 Answer
Fastest Way To Save/Load a SkinnedMeshRenderer at Runtime 0 Answers
Why Are My Project Assets Constantly Re-Importing? 2 Answers
How to highlight or select an asset in project window from editor script? 2 Answers
Can't drag and drop assets to editor. 6 Answers