CustomValueDrawer on class uses wrong/unexpected scope

Issue #908 invalid
Warwick Allison created an issue

1. What happened?

When applying the CustomValueDrawer attribute to a class, the scope of the member is still the scope of the user of the class, not the class to which the attribute is applied.

2. How can we reproduce it?

Add this component (OdinBugExample.cs) to a Unity GameObject. Observe that an error is given. Change the attribute to say “Draw2” and it uses that method, which is not in the scope of OtherClass.

Expected behaviour is to use the one in OtherClass.

I tried fully qualifying: [CustomValueDrawer("OtherClass.Draw1")]

The workaround is to make a passthrough method in OdinBugExample and put the attribute there, not in OtherClass.

It seems that this attribute doesn’t really work on a class, but the error for doing so is unhelpful.

using Sirenix.OdinInspector;
using System;
using UnityEditor;
using UnityEngine;

[Serializable]
[CustomValueDrawer("Draw1")]
public class OtherClass
{
    public int foo;
    public static void Draw1(OtherClass oc, GUIContent label)
    {
        GUILayout.Label("Draw1");
        EditorGUILayout.IntField(label, oc.foo);
    }

}

public class OdinBugExample : MonoBehaviour
{
    public OtherClass test;

    public static void Draw2(OtherClass oc, GUIContent label)
    {
        GUILayout.Label("Draw2");
        EditorGUILayout.IntField(label, oc.foo);
    }
}

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

The error is:

Could not match the given string 'Draw1' to any possible value resolution in the context of the type 'OdinBugExample'. The following kinds of value resolutions are possible:

C# Expressions: "@expression"
Member References: "MemberName"

And the following named values are available:

label (GUIContent)
callNextDrawer (Func<GUIContent, bool>)
property (InspectorProperty)
value (OtherClass)
root (OdinBugExample)

4. What version of Unity are you using?

2022.1.15.f1

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

3.1.10.0 (not listed in options here)

6. Do you have Editor Only mode enabled?

No.

7. What operating system are you on?

Windows 11.

Comments (2)

  1. Lucas Schwaner

    Hey, this is possible using this expression: "@OtherClass.Draw1($value, $label)", you could also do "@$value.Draw1($value, $label)" if the Draw1 method wasn't static.

  2. Warwick Allison reporter

    The issue is not that it's impossible - yes, there are workarounds.

    The issue is that it's not at all what anyone would expect from a class attribute.

    If leaving terrible error messages and obtuse behaviour is fine, then yes, the issue is closed.

  3. Log in to comment