Toggle <X> is not part of ToggleGroup <Y>

I’m getting this error, only occasionally, in my Console.

This is a pop-over window that I’m enabling, and in OnEnable(), I’m also setting the state of the Toggles on the screen. The Toggle is indeed part of the ToggleGroup, both before the game is Played, as well as seen in the Inspector, immediately after the error occurs. And, even though the Console claims the Toggle isn’t part of the group, once the window appears the Toggles all work as expected.

I suspect that this is a bit of a timing issue; that the window is almost Enabled, and that its children aren’t quite Enabled enough to be properly manipulated. This is based on another issue I’m seeing, where I attempt to Enable or Disable certain child objects on a different window’s OnEnable().

This is in beta20.

Ditto, started getting this error out of the blue. All References to togglegroup are broken.

Same here… ToggleGroup broken in b21. Guess we need to wait for the next beta :frowning:

Current workaround - Associate toggle with toggle group in code- runtime.

Verified in B21 here as well, error from console is: 2015-02-04_1515 .

Interestingly, this problem does not occur with a standard windows build - I’m only seeing it in the Web Player builds.

lilboylost - what does that code look like for you? I’m using the following script attached to a Toggle (assign the reference to ToggleGroup) and not getting any love:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class ToggleFix : MonoBehaviour
{
    public ToggleGroup group;

    void Start( )
    {
        Toggle toggle = GetComponentInChildren<Toggle>( );
        toggle.group = group;
    }
}

for now i’ll just use a custom solution with the toggles, seems webplayer related but i’m building out to webplayer atm for testing so i’d like it to work :).

Try assigning it in OnEnable

privateToggletoggle;
voidAwake() {
toggle = this.GetComponent<Toggle>();
 }

voidOnEnable () {
toggle.group = buggyGroup;
 }

Thanks, will do!

Just hit this exception in Unity 5.1.3f1 when I set the ‘Group’ Inspector field of a Toggle by manually dragging the ToggleGroup component into it.

To fix it, I had to first call RegisterToggle on the ToggleGroup and pass in the Toggles when I was instantiating them from the code.

2 Likes

@dreasgrech is the correct answer.
Thank you!

I know this is an old post, but if someone finds it useful… I had the same error in Unity 2019.
The code was working properly up to Unity 2018, then started to fail when assigning the Toggle.group property.
The solution was to UnregisterToggle() before deleting its GameObject (Toggle included), then new items (with toggles) will let you set the Toggle.group properly.

This is a known issue: Unity Issue Tracker - Re-enabling game object with &quot;Toggle group&quot; loses information about previously checked toggle