Custom PropertyDrawer/Editors with typeof raw generics does not work with odin

Issue #904 resolved
jackie engberg created an issue

Hey I'm currently trying to make a compatibility patch to a plugin I'm working on but it seems that I've found some bugs which I'll try to report in here.

First I must stress that the plugin seems to draw my editors and properties correctly without Odin installed. Secondly, I'm currently using unity 2020.3.1f1 and Odin 3.1.10 (january 11th release) to test my plugin.

1. What happened?

PropertyDrawers with raw generic types seems to be ignored by odin, eg. [CustomPropertyDrawer(typeof(GenericReference<>), true)]

2. How can we reproduce it?

First create a generic class like this:

using UnityEngine;

[System.Serializable]
public class GenericReference<T>
{
    [SerializeField]
    protected T value1;
    [SerializeField]
    protected T value2;
}

Next we create a custom property drawer placed inside an editor folder which should draw the inspector for the above GenericReference class lie so.

using UnityEditor;
using UnityEngine;

[CustomPropertyDrawer(typeof(GenericReference<>), true)]
public class GenericReferencePropertyDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        Debug.Log("Generic Drawer has been called!");
        EditorGUI.LabelField(position, "If this is displayed this drawer should work!");
    }
}

Lastly create a monobehavior where we can test the drawer:

using UnityEngine;

public class TestInspector : MonoBehaviour
{
    [SerializeField]
    GenericReference<string> _test1;
    [SerializeField]
    GenericReference<int> _test2;
}

Further info:

Changing GenericReference<> into GenericReference<string> seem to work but this would require a lot of boilerplate code to be created,

3. If screenshots would help explain or demonstrate your issue, please include these.

What Odin draws:

Expected editor (without odin):

4. What version of Unity are you using?

unity 2020.3.1f1 currently but also occurs on new versions.

5. What version of Odin are you using? (See "Tools > Odin Inspector > About")

3.0.13.0 (although asset store says 3.1.10 (january 11th release))

6. Do you have Editor Only mode enabled?

No.

7. What operating system are you on?

Windows 10

Comments (6)

  1. Log in to comment