Logo
UI Elements

Radio Button Group

A simple button group controller

Overview

Radio Button Group manages a collection of Button components placed under the same parent and ensures that only one button is selected at a time. It automatically detects Button components in direct children, assigns index based listeners, updates their interaction states, and sends selection change events.

The group supports optional deselection, allowing all buttons to be unselected if the user clicks the selected one again.


Usage

Add Radio Button Group to a parent object

Place Button components as direct children

Clicking any button will:

  • Deselect the previously selected button
  • Select the new one using and make its state Selected
  • Invoke OnSelectionChanged with the index

Properties

NameTypeDescription
selectedIndexintCurrently selected button index, or -1 if none
allowDeselectionboolAllows clicking the selected button again to clear selection
onSelectionChangedUnityEvent<int>Fires when selection changes (or -1 when cleared)

Public Methods

NameParametersDescription
Initialize()NoneRebuilds button references and listeners
SetButton(index)intSelects the button at index
DeselectAll()NoneClears the current selection
IsButtonSelected(index)intReturns true if index is selected
SetInteractable(value)boolEnables or disables all buttons

Code Example

RadioButtonGroupExample.cs
using UnityEngine;
using Evo.UI;

public class RadioButtonGroupExample : MonoBehaviour
{
    public RadioButtonGroup group;

    void Start()
    {
        // Listen to change
        group.onSelectionChanged.AddListener(index =>
        {
            Debug.Log("Selected index: " + index);
        });

        // Select button manually
        group.SetButton(1);

        // Deselect all
        group.DeselectAll();

        // Disable whole group
        group.SetInteractable(false);
    }
}

On this page