BeginProperty doesn't work properly with multiple fields?

Hi all

I’ve been having a lot of trouble recently getting prefab overrides working correctly in my custom inspectors.

I have been following the PropertyDrawer documentation available here.

The current issue involves a custom PropertyDrawer that displays two child fields:

alt text

(int field and enum popup)

This is instantiated from a prefab so I can test the override:

alt text

When I change the value in the enum field the label will become bold, signifying the value is different to the source prefab. However, when I adjust the value in the int field the label does not change:

alt text

The OnGUI method is as follows:

public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
{
    // Begin the property
    label = EditorGUI.BeginProperty(position, label, prop);

    // Draw the label
    position = EditorGUI.PrefixLabel(position, label);

    // Undo indentation
    int indentation = EditorGUI.indentLevel;
    EditorGUI.indentLevel = 0;

    // Position rects
    Rect rangeModePosition = new Rect(position);
    rangeModePosition.x += (rangeModePosition.width - 12);
    rangeModePosition.width = 12;

    Rect rangeModeFieldsPosition = new Rect(position);
    rangeModeFieldsPosition.width -= (rangeModePosition.width + HydraEditorUtils.STANDARD_HORIZONTAL_SPACING);

    // Fields
    EditorGUI.PropertyField(rangeModePosition, prop.FindPropertyRelative("m_RangeMode"), GUIContent.none);
    EditorGUI.PropertyField(rangeModeFieldsPosition, prop.FindPropertyRelative("m_ConstValueA"), GUIContent.none);

    // Reset indentation
    EditorGUI.indentLevel = indentation;

    EditorGUI.EndProperty();
}

In the above code the enum field is drawn in the inspector first. If I swap the order of the fields I get the opposite behaviour:

alt text

So my questions are:

  1. Is there something obviously wrong with my code? There is no C# example in the script reference, so I’ve had to port from Javascript.
  2. Is there something wrong with the Javascript documentation? You’ll notice the example calls BeginProperty without actually using the output GUIContent label.
  3. Does BeginProperty only cover the first following property field? In this case, do I need to call BeginProperty for each individual property field?

Thanks in advance for any advice.

I’m not sure why, but I’m getting the desired results after changing:

position = EditorGUI.PrefixLabel(position, label);

to

position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);