Search Unity

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

Discussion in 'UGUI & TextMesh Pro' started by Crwth, Oct 21, 2014.

  1. Crwth

    Crwth

    Joined:
    Mar 1, 2014
    Posts:
    6
    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.
     
  2. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
    Ditto, started getting this error out of the blue. All References to togglegroup are broken.
     
  3. Ricks

    Ricks

    Joined:
    Jun 17, 2010
    Posts:
    650
    Same here... ToggleGroup broken in b21. Guess we need to wait for the next beta :(
     
  4. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
    Current workaround - Associate toggle with toggle group in code- runtime.
     
  5. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    Verified in B21 here as well, error from console is: http://screencast.com/t/FPYnZ5Fr7 .

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

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    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:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. using System.Collections;
    5.  
    6. public class ToggleFix : MonoBehaviour
    7. {
    8.     public ToggleGroup group;
    9.  
    10.     void Start( )
    11.     {
    12.         Toggle toggle = GetComponentInChildren<Toggle>( );
    13.         toggle.group = group;
    14.     }
    15. }
    16.  
    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 :).
     
  7. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
    Try assigning it in OnEnable
    Code (csharp):
    1.  
    2. privateToggletoggle;
    3. voidAwake() {
    4. toggle = this.GetComponent<Toggle>();
    5.  }
    6.  
    7. voidOnEnable () {
    8. toggle.group = buggyGroup;
    9.  }
     
  8. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    Thanks, will do!
     
  9. dreasgrech

    dreasgrech

    Joined:
    Feb 9, 2013
    Posts:
    205
    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.
     
    chilemanga and sebagork like this.
  10. chilemanga

    chilemanga

    Joined:
    Apr 19, 2013
    Posts:
    4
    @dreasgrech is the correct answer.
    Thank you!
     
  11. jemonsuarez

    jemonsuarez

    Joined:
    Sep 24, 2012
    Posts:
    151
    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.
     
  12. Circool

    Circool

    Joined:
    Feb 5, 2013
    Posts:
    56