In a custom inspector, I have a bitfield that I set with EditorGUILayout.MaskField, but I get a wierd behaviour when I’m multi-editing prefabs: the value of the last selected prefab overide the value of every prefabs, if I don’t put the changeCheck, prefabs get messed as soon as I select them.
Am I doing something wrong ?

    [CustomEditor(typeof(Module))]
    [CanEditMultipleObjects]
    public class ModuleDrawer : Editor
    {
        SerializedProperty _serializedBitField  ;
    
        void OnEnable()
        {
            _serializedBitField  = serializedObject.FindProperty("_bitField ");
        }
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();
        
            EditorGUI.BeginChangeCheck();
            _serializedBitField.intValue =  EditorGUILayout.MaskField("BitField", _serializedBitField.intValue, randomStringArray);
            if (EditorGUI.EndChangeCheck())
                serializedObject.ApplyModifiedProperties();
        }

Well, multi object editing is generally a bit tricky. To avoid unwanted changes you must prevent the assignment to _serializedBitField.intValue. Whenever you assign a value here the serialized object / property will set the value for all objects represented by the SerializedObject.

One straight forward way would be:

int newVal = EditorGUILayout.MaskField("BitField", _serializedBitField.intValue, randomStringArray);
if (newVal !=_serializedBitField.intValue)
    _serializedBitField.intValue = newVal;

This way you only actually change the value when you tinker with the maskfield UI. However for multiobject editing it’s usually common to visually show the user that the property has multiple values.

Most editor controls which support multiediting internally check SerializedProperty.hasMultipleDifferentValues and replace the shown content by a dash. Of course that is not possible with the maskfield. You may just display an additional warning box if “hasMultipleDifferentValues” is true. Another solution is to simply omit the whole maskfield if you’re editing multiple objects with different values and just show an info box instead.

Note that if you’re editing multiple different values, the value that is returned when you read intValue is just the value of the first object. Unfortunately the SerializedProperty doesn’t provide a way to read or write the individual values.

Here’s a way to convert the generated int from the EditorGUILayout.MaskField back to the array