PropertyDrawer not working on ScriptableObjects

Property drawers are working for MonoBehaviours but not for ScriptableObjects. Is this a bug or was it never supported?

I’ve tried this on both 2020.2.3f1 and 2020.2.5f1 to no avail.

In a fresh project I define a ScriptableObject:

[CreateAssetMenu]
public class MyVar : ScriptableObject
{
    public float myProperty;
}

I create a property drawer:

[CustomPropertyDrawer(typeof(MyVar))]
public class MyVarDrawer : PropertyDrawer
{
    public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
    {
        EditorGUI.LabelField(pos, "Custom Property Drawer is working!");
    }

    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        return EditorGUIUtility.singleLineHeight;
    }
}

If I reference MyVar in a MonoBehaviour it works and I can see my custom label in the inspector, but If I create an asset of MyVar it renders without the custom property drawer.

First I thought this was by design but I’m finding more and more old threads where they got it working so I’m starting to think it’s a bug: CustomPropertyDrawer on Scriptable Object

In this case, the MyVar instance is a property of your MonoBehaviour. So the custom property drawer is used.

In this case, your asset is not being drawn as a property, so the custom property drawer is not used.

1 Like

I figured it was something like that but all the historic posts on the issue was confusing.Thanks for your time!