Property drawer: Multiple selection in prefabs override/replace other prefabs' values

My property drawer has a reference to an object:

        _vfx.objectReferenceValue = EditorGUI.ObjectField(position, _vfx.objectReferenceValue, typeof(VFX), false);

If I select a prefab that uses this property and then multi-select more prefabs that also use this property they will get their own “vfx” value overridden by the first selection’s value.

It also does this with my enums:

    _type.intValue = (int)(EnemyType)EditorGUI.EnumPopup(position, (EnemyType)_type.intValue);

What do I need to do so multi-selected prefabs retain their own value?

I just noticed exactly this problem on our project. It is likely a bug introduced in the most recent versions of Unity. I made a quick workaround using SerializedProperty.hasMultipleDifferentValues, which tells me when multi-editing is taking place. When that’s the case, I just switch to default property drawing using EditorGUI.PropertyField()

Because you should do :

GUI.changed = false;
var value = (int)(EnemyType)EditorGUI.EnumPopup(position, (EnemyType)_type.intValue);
if ( GUI.changed )
	_type.intValue = value;

This is still a problem. I worked around it like this:

[CustomPropertyDrawer(typeof(Layer))]
class LayerDrawer : PropertyDrawer {
    public override void OnGUI(
      Rect position,
      SerializedProperty property,
      GUIContent label
    ) {
      property.Next(true);
      var nextValue = EditorGUI.LayerField(position, label, property.intValue);
      if (nextValue != property.intValue) {
        property.intValue = nextValue;
      }
    }
  }
}

This way only if the user actually changes the value will it be assigned, which in the case of a multi-selection will affect all selected objects as expected.