ToggleGroup issues

Since I haven’t found anything on this forum or in docs, here’s a thread for other developers fighting this awkward component.

No matter if you have some toggles set to isOn on scene or switched them on from code:

  • ActiveToggles() will be empty if called from OnEnable(), same for AnyTogglesOn()
  • SetAllTogglesOff() is not working from OnEnable()

It looks like every Toggle registers and unregisters from its group on every enable/disable. That’s why there’s no obvious method like AllToggles() but only ActiveToggles().

So if you need to call these methods inside OnEnable() then use StartCoroutine() and call them after yield return new WaitForEndOfFrame();

Now the worst part: if you’d like to dynamically set one of your toggles on then you need to keep a separate list of references to your Toggle components.

6 Likes

Any news on this issue? It’s annoying that I can’t rely on ActiveToggles() in OnEnable.

I think this is still a problem.

2 Likes