Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

ToggleGroup and events

Discussion in 'UGUI & TextMesh Pro' started by GarethIW, Aug 22, 2014.

  1. GarethIW


    Jun 24, 2014
    I'm probably missing something simple here.

    You can add an event to a single Toggle control. The ToggleEvent passes a bool to your receiving method, but nothing more. This is fine for a single toggle that you just want to react to when it's toggled on and off.

    When you have a toggle group, especially one into which you have instantiated the items yourself, it would be useful to be able to have one delegate to receive the onchange event for all of the Toggles in the group. We can't use ToggleEvent for this as it doesn't include a reference to the Toggle gameobject.

    Is there currently a way to do this?
  2. Tim-C


    Unity Technologies

    Feb 6, 2010
    When you create your toggle / group or add the callback you can do this with a delegate as you have access to the toggle and the group at that stage. The example below is for button, but the same ideas can be applied to toggle.

    Code (csharp):
    2. button.onClick.AddListener (delegate { Debug.Log("The Button is " +; } );