2
\$\begingroup\$

I have a class like this:

public class NoiseMap : ScriptableObject
{
    public string Hello()
    {
        //...
    }
}

Now I am building its custom editor:

[CustomEditor(typeof(NoiseMap))]
public class NoiseMapEditor : Editor
{

    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        // How to call Hello() ???

        serializedObject.ApplyModifiedProperties();
    }

}

I would like to get the value of the method Hello. How could I achieve this?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Presumably you already read the docs and tried casting the targetObject to your type? Did that not have the expected effect? \$\endgroup\$
    – DMGregory
    Jan 19, 2019 at 17:53

1 Answer 1

2
\$\begingroup\$

you're really close. You just need to get a target reference to the main script like so:

public override void OnInspectorGUI()
{
    NoiseMap noiseMap = (NoiseMap)target;

    //then you can reference it like so:

    noiseMap.Hello();
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .