Prefab modification is not in bold text when using polymorphic custom drawer

Issue #298 open
Rain Lai
created an issue

Say we have a field, of which the type is a List of polymorphic types.

public class Test : SerializedMonoBehaviour
 {
    public List<A> aa;
 }

 public interface A
 {
 }

 [Serializable]
 public class B : A
 {
    public float value;
 }

And a custom draw to draw it:

 [CustomPropertyDrawer(typeof(B))]
 public class SimpleDrawer : PropertyDrawer
 {
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.PropertyField(position, property.FindPropertyRelative("value"), new GUIContent("VALUE: "));
    }
 }

Odin correctly uses SimpleDrawer to draw the elements of aa. But after I put Test script on a game object and made it a prefab, I added a B into it, apply prefab, change the value of value, and it was not bolded.

Odin version: 1.0.6.1

Expect Result: value property is bolded.

Actual Result: Nothing is bolded.

Note that when I add or remove elements from list it's bolded as expected, but when I change the value of a property of an element it doesn't work. Also it works normally for non-polymorphic list.

Comments (7)

  1. mSkull001

    I'm unable to replicate this in the current internal version of 1.0.6.1 and in Unity 5.3.0.

    Which version of Unity is this issue happening?

    If you send us your invoice number to us by mail, we can send you the latest build of 1.0.6.1, so you can test if the issue has been resolved.

  2. Rain Lai reporter

    I'm already using Odin 1.0.6.1. My Unity version is 2017.3.1f1 and my OS is macOS 10.13.3.

    That being said, I'm struggling to reproduce this bug too. I'll investigate further later.

  3. Rain Lai reporter

    Ok I got it. There was a bug in the code I posted. It actually used Unity's default drawer rather than my custom drawer so of course everything worked.

    Use this:

     [CustomPropertyDrawer(typeof(B), true)]
     public class SimpleDrawer : PropertyDrawer
     {
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.PropertyField(position, property.FindPropertyRelative("value"), new GUIContent("VALUE: "));
        }
     }
    

    To reproduce the behavior I reported.

    Sorry for the confusion.

  4. Rain Lai reporter

    It's very weird. The second argument of CustomPropertyDrawer has no reason to affect this. Actually even when it's false, Odin uses my custom drawer correctly, but the bug disappears. This behavior is 100% consistent on my machine.

    In my use case, however, I have subclasses of B, so I cannot simply set it to false.

  5. mSkull001

    Yes, that made the difference. I can reproduce the issue now.

    Secondly, the int field seems to have gotten stuck after changing the value a bit. Not sure what I did to make that happen, but clearly this is something that needs looking into.

  6. Log in to comment