Is it possible to create a Material _asset_ from a script?

Hi,

I know how to create a temp material for a game object, but is it possible to create a new asset within a script?

I want to be able to do this as part of an editor script I'm writing.

Thanks

Steve

Check out AssetDatabase.CreateAsset - it'll turn an instance of a material into an Asset in the project

http://unity3d.com/support/documentation/ScriptReference/AssetDatabase.CreateAsset.html

(Even has a material example for you)

 @MenuItem("GameObject/Create Material")
static function CreateMaterial () {
    // Create a simple material asset
    var material = new Material (Shader.Find("Diffuse"));
     AssetDatabase.CreateAsset(material, "Assets/" + Selection.activeGameObject.name + ".mat");
}

using UnityEngine;
using UnityEditor;

public class CreateMaterialExample : MonoBehaviour
{
    [MenuItem("GameObject/Create Material")]
    static void CreateMaterial()
    {
        // Create a simple material asset

        Material material = new Material(Shader.Find("Specular"));
        AssetDatabase.CreateAsset(material, "Assets/MyMaterial.mat");

        // Print the path of the created asset
        Debug.Log(AssetDatabase.GetAssetPath(material));
    }
}

How do you assign the albedo from another file?