Horizontally scrollable row of colour-tinted toggle buttons for multi-select.
Formsformstogglegroupcolormulti-select
Summary
ColorToggleGroup manages a set of ColorToggleButton items as a single-selection group. It supports both tap-to-select and drag-to-select gestures, ensuring that only one color is selected at a time. Selection state is coordinated internally; consumers only need to respond to OnColorSelected.
Typical use cases:
Full-screen or inline color pickers
Theme or accent color selectors
Tag or category color selectors
Properties
Name
Description
Options
Colors
Gets or sets the array of colors represented by the group. Changing this value rebuilds all child buttons.
Color[]
SelectedColor
Gets the currently selected color. null if nothing is selected.
Color? (nullable)
Alignment
Controls the flex direction of the buttons container.
FlexDirection
USS Classes
Class
Description
colorToggleGroup
Root element.
colorToggleGroup__container
Flex container that holds all ColorToggleButton children.
Events
Name
Description
Arguments
OnColorSelected
Fired when the user selects a color by tap or drag. Not fired when selection changes programmatically via SelectColor(color, propagateEvent: false).
Color selectedColor
Public Methods
Signature
Description
DeselectAll()
Clears the current selection without firing OnColorSelected.
Programmatically selects the button whose color matches. Pass propagateEvent: false to suppress OnColorSelected.
Using the Control
Inline Color Picker
usingUnityEngine;usingUnityEngine.UIElements;usingUnityUIToolkit.Extensions;publicclassThemeSelectorController:MonoBehaviour{[SerializeField]privateUIDocument_document;privateColorToggleGroup_colorGroup;privateColor_currentThemeColor=Color.white;privatevoidOnEnable(){varroot=_document.rootVisualElement;_colorGroup=newColorToggleGroup();_colorGroup.Colors=new[]{newColor(0.91f,0.27f,0.38f),newColor(0.25f,0.56f,0.96f),newColor(0.18f,0.80f,0.44f),newColor(0.98f,0.75f,0.18f),newColor(0.60f,0.20f,0.80f),};_colorGroup.Alignment=FlexDirection.Row;_colorGroup.OnColorSelected+=OnThemeColorPicked;root.Q<VisualElement>("colorPickerContainer").Add(_colorGroup);// Pre-select the saved theme color without firing the event_colorGroup.SelectColor(_currentThemeColor,propagateEvent:false);}privatevoidOnThemeColorPicked(Colorcolor){_currentThemeColor=color;Debug.Log($"Theme color changed to {color}");// Apply color to your UI here}privatevoidResetSelection(){_colorGroup.DeselectAll();}}