Can't access Inspector variable in C# Editor script?

Hi,

I'm trying to create an Editor script that uses a reference to a Material in the Inspector.

In the following code, the variable 'myMat' appears in the Inspector, but I get an error "An object reference is required to access non-static member `TestScript.myMat'" at the end where I am trying to access the variable. If I make myMat static, I no longer get the error, but myMat is not shown in the Inspector.

using UnityEngine;
using UnityEditor;
using System.Collections;
[System.Serializable]

public class TestScript : ScriptableObject 
{
    public Material myMat;

    class OtherClass 
    {
        public OtherClass (Material mat) 
        {
            Material classMat = mat;
        }
            public MakeStuff(/*Big function that makes stuff with myMat*/); 
    }

    [MenuItem ("GameObject/TestScript")]
    static void MenuTestScript()
    {
        OtherClass newClass = new OtherClass(myMat);
            newClass.MakeStuff();

    }   
}

Is there a way to satisfy both? Thanks.

A little more background on what you're specifically trying to do would be helpful.

Are scriptable wizards out of the question for your needs? http://unity3d.com/support/documentation/ScriptReference/ScriptableWizard.html If you want an editor script to "do something" with a material, you can do that pretty easily.

AFAIK, static variables are simply not serializeable. You will need to actually create a TestScript object instance in order to get hold of that value.

e.g.

static void MenuTestScript()
{
    TestScript test = new TestScript();
    OtherClass newClass = new OtherClass(test.myMat)
}

(Of course you may need to refactor your classes if you already use a TestScript instance for other purposes).