Question about Custom Editor Multi-object editing

When I select multiple objects that are using EditorGUILayout.PropertyField, I get a “-” Dash in the editor indicating that the selected fields have different values. Now if I do the same with EditorGUILayout.IntField or others, the same does not happen.

EditorGUILayout.PropertyField(fontSize_prop); // Works as expected and "Dash" shown for different values.

EditorGUILayout.IntField("Line Lenght:", lineLenght_prop.intValue); // No "Dash" shown with multi objects off different values.

Is this expected behavior?

Does this mean I need to manually check SerializedProperty.hasMultipleDifferentValues and then deal with the results accordingly?

I discovered that some of the EditorGUILayout Class Functions do take serialized properties as parameters and in those instances, the “Dash” does show up to indicate the multi selection contains different values.

Although this is not reflected in the documentation, IntSlider is a function that accepts Serialized Properties.

 public static void IntSlider(SerializedProperty property, int leftValue, int rightValue, GUIContent label, params GUILayoutOption[] options);
 public static void IntSlider(SerializedProperty property, int leftValue, int rightValue, string label, params GUILayoutOption[] options);

So a quick question to the Unity Gods, is why haven’t the other functions like IntField or FloatField and the rest been updated to accept Serialized Properties and is there a plan to do in the near term?

Edit: I realize that I could use

 public static bool PropertyField(SerializedProperty property, params GUILayoutOption[] options);

but in cases where you which to apply a style, that is not possible. Functions like IntField for instance do accept a style which is handy.

Still hoping for an answer / feedback :wink:

Me too!!!
Why are questions like these left to gather dust?

You have to use EditorGUI.showMixedValue = prop.hasMultipleDifferentValues;

1 Like

Or EditorGUI.Begin/EndProperty, to get the whole shebang for “free”.

1 Like