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 '19 at 17:53
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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.