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

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.

You may want to look into the AssetDatabase class.