Legacy Documentation: Version 5.3
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorGUI.showMixedValue

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static var showMixedValue: bool;
public static bool showMixedValue;

Description

Makes the following controls give the appearance of editing multiple different values.

This is sometimes useful when creating custom editors and you want to represent a value in a non-standard way in the GUI while also supporting multi-object editing.

	// This example shows a custom inspector for an object "MyVessel".
	// MyVessel has a boolean variable isFast but we want to show it
	// as a dropdown instead of as a toggle.
	
	enum SpeedOption { Slow, Fast }
	
	@CustomEditor (MyVessel)
	@CanEditMultipleObjects
	class MyVesselEditor extends Editor {
		var isFastProp : SerializedProperty;
		
		function OnEnable () {
			isFastProp = serializedObject.FindProperty ("isFast");
		}
		
		function OnInspectorGUI () {
			serializedObject.Update ();
			
			// Show the isFast boolean the standard way - as a toggle:
			EditorGUILayout.PropertyField (isFastProp);
			
			// Show the isFast boolean as a dropdown using the SpeedOption enum defined above:
			
			// Check if the value was changed inside this block
			EditorGUI.BeginChangeCheck ();
			
			// If the isFast property represent multiple different values, the dropdown should show that:
			EditorGUI.showMixedValue = isFastProp.hasMultipleDifferentValues;
			
			// Convert the isFast boolean to an enum value
			var speedOptionEnumValue : SpeedOption;
			if (isFastProp.boolValue == true)
				speedOptionEnumValue = SpeedOption.Fast;
			else
				speedOptionEnumValue = SpeedOption.Slow;
			
			// Present the enum value in a dropdown:
			speedOptionEnumValue = EditorGUILayout.EnumPopup ("Speed", speedOptionEnumValue);
			
			// Set showMixedValue to false so it doesn't affect the following controls, if any:
			EditorGUI.showMixedValue = false;
			
			// If the value was changed inside this block, apply the new value to all the objects:
			if (EditorGUI.EndChangeCheck ())
				isFastProp.boolValue = (speedOptionEnumValue == SpeedOption.Fast ? true : false);
			
			serializedObject.ApplyModifiedProperties ();
		}
	}
	// This is the MyVessel script used above
	
	var isFast : boolean = false;
	
	function Update () {
		// Update logic here...
	}