Odin is not rendering custom PropertyDrawer

Issue #81 resolved
Bruno Tachinardi created an issue

Odin ignores our custom PropertyDrawers, making it incompatible with inspectors that need more advanced logic that Odin can't handle.

What makes this even more aggravating is the fact that PropertyDrawers can render in multiple Scripts (any MonoBehaviour that uses the target Class), so disabling Odin from creating custom editors for specific scripts is a terrible workaround, specially if the property being drawn is a core piece of your game code.

[CustomPropertyDrawer (typeof (MyClass))]
public class MyClassPropertyDrawer : PropertyDrawer {
    public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
        // Code in here won`t render when Odin creates custom editors for behaviours that use MyClass as a public field
}

Comments (1)

  1. Tor Esa Vestergaard

    We've duplicated this error and a fix should be making it into the next patch after 1.0.1.5. The issue was that the regular drawer that draws all "composite values" that consist of multiple properties to draw, was accidentally being assigned a priority of (0, 0, 1), which is above the default priority of converted Unity property drawers (0, 0, 0.5). The bugfix correctly sets the composite drawer priority to (0, 0, 0) again.

    Meanwhile, you can mark your drawers with a drawer priority attribute, and set it higher than the composite drawer, like so:

    [CustomPropertyDrawer(typeof(MyClass))]
    [DrawerPriority(0, 0, 1.5)]
    public class MyClassPropertyDrawer : PropertyDrawer
    {
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Drawing code here
        }
    }
    

    This will cause your drawer to have a higher priority, and thus draw before the composite drawer (which, as a rule, does not invoke the next drawer in line).

    Also, as an aside note, if you mark any member with Odin's [ShowDrawerChain] attribute, you can see all drawers for that member, and their priority: http://prntscr.com/fa2vf5

  2. Log in to comment