Search Unity

Possible PropertyDrawer Bug?

Discussion in 'Immediate Mode GUI (IMGUI)' started by lverhoef, Jan 21, 2015.

  1. lverhoef

    lverhoef

    Joined:
    Jan 15, 2015
    Posts:
    13
    Hey all, I've been working with PropertyDrawers lately, and I ran into some strange behavior I can't figure out how to work around. Basically, multi-selection seems to set all of the values to match the latest selected one, rather than doing what Unity does elsewhere, where you get a line through the value.

    Anyway, with these classes:

    Code (CSharp):
    1. [System.Serializable]
    2. public class TestNodeData {
    3.     public GameObject obj;
    4. }
    5.  
    6. public class TestNode : MonoBehaviour {
    7.     public TestNodeData data;
    8.     public GameObject objNormal;
    9. }
    and this PropertyDrawer

    Code (CSharp):
    1. [CustomPropertyDrawer( typeof( TestNodeData ))]
    2. public class TestNodeDrawer : PropertyDrawer {
    3.  
    4.     public override void OnGUI( Rect position, SerializedProperty property, GUIContent label ) {
    5.         SerializedProperty objProperty = property.FindPropertyRelative( "obj" );
    6.         objProperty.objectReferenceValue = EditorGUI.ObjectField( position, objProperty.displayName, objProperty.objectReferenceValue, typeof( GameObject ), true );
    7.     }
    8. }
    I can reliably replicate the problem. Here's what happens:

    Object 1 and Object 2 have different reference values.
    PD1.png

    Both are selected. The reference not through the PropertyDrawer has a strikethrough, the one through the PropertyDrawer displays the value of the most recently selected object.
    PD2.png

    When you deselect the objects and re-select Object 1, the value exposed through the PropertyDrawer is set to the value Object 2 had. Oops.
    PD3.png

    Is there something dumb and obvious I'm forgetting to do here? There's a SerializedProperty.hasMultipleDifferentValues variable I can access, but I can't figure out anything smart to do with it other than just lock off editing when it's true. Has anyone else run into this?