Search Unity

Allow Toggle Group to Have No Active Toggle

Discussion in 'UGUI & TextMesh Pro' started by Marble, Aug 24, 2014.

  1. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,244
    A Toggle that belongs to a ToggleGroup should be able to be set to isOn = false via script. Right now, doing so has no effect, even though the field is public. The result would be that a ToggleGroup could have no active Toggle.

    At the very least, it's inconsistent that a ToggleGroup will permit its Toggles to all be isOn == false at Start but not if one is enabled and then disabled again during runtime.
     
    rakkarage and User340 like this.
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    2,979
    Yes, please! In desperate need of this right now!
     
  3. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,163
    What is a use case for this? A group should have one option selected as you are choosing between the options.
     
  4. Alahmnat

    Alahmnat

    Joined:
    Feb 1, 2008
    Posts:
    13
    As someone who's had this request come up in more than a few web development projects myself, it's about forcing the user to consciously make a choice, rather than essentially skipping the field entirely and being able to click through with the default value of the radio button list selected.
     
    ortin and Marble like this.
  5. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,244
    Also, it allows one to use the Toggle behavior for groups of GUI elements. If I have options buttons for audio, graphics, and controls on the side of the screen during gameplay, I would conceivably only want one group of settings open at a time—or none open at all.

    One can code this, but the Toggle behavior is right there.
     
    rakkarage likes this.
  6. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    2,979
    My situation is similar to Marble's. I'm using a Toggle Group for menus, and allowing one menu to be showing at a time. It works great except that forces one of the menus to be open no matter what. I would like it to be one menu visible or no menus visible.
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,788
    Just thinking aloud. One possible work around would be to add an extra 'show nothing' toggle to the toggle group. You could even place this off screen if you wanted the effect to be managed via code.
     
  8. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    2,979
    That is definitely a solid workaround as of right now. One limitation of it however is that it still doesn't allow you to disable a toggle by pressing it.
     
  9. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,788
    I haven't actually had much cause to play with the toggle groups yet. Is it possible to tie into the OnClick event of the individual toggle, then select the 'show nothing' toggle from there?

    We are starting to sound pretty hacky now...
     
  10. Aurecon_Unity

    Aurecon_Unity

    Joined:
    Jul 6, 2011
    Posts:
    241
    I also have a need for this. My use case is that I have a menu system where you can select menu items to bring up windows populated with various UI elements. However the user should only be able to select one menu item at a time, or none at all (to free up screen space). So, much like the other uses listed here.

    It's important to note that NGUI caters to this with an option on the checkbox item called 'State of none', where ticking it allows the group to have no toggle selected.

    Whilst certainly not a deal breaker, it would be good to at least aim to achieve feature parity with the competition and this seems like a pretty easy one, that has been requested and discussed a fair few times already.

    Thanks!
     
    rakkarage likes this.
  11. JAKJ

    JAKJ

    Joined:
    Aug 17, 2014
    Posts:
    185
    I just think it's bad software ergonomics to have a set of radio buttons without one selected: In order for a UI to be considered "good", it should be intuitive and follow the conventions that users have come to expect. Checkboxes toggle, radio buttons select one at a time, and that's just how those UI elements work.

    Users should not need to re-learn how to use standard UI components between programs, so you should not have this deviance: Have a "none" radio button the user can select.
     
    akingdom likes this.
  12. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    Toggle group != radio buttons
     
  13. Cripplette

    Cripplette

    Joined:
    Sep 18, 2012
    Posts:
    66
    I have a toolbar for my game where the player can select a tower to construct. Only one tower can be active at a time, so I use a toggle group for it. But I would like to be able to have no tower selected too !
     
  14. JAKJ

    JAKJ

    Joined:
    Aug 17, 2014
    Posts:
    185
    They are designed to have one thing selected at a time. That is exactly what radio buttons are. That is why they are called "radio buttons": They are like the buttons on a radio (which existed before computers did), where you press one and the others come back up. It makes no sense to have no radio station selected.

    When a user looks at a UI element, they should easily and immediately know how to use it: A button performs an action, a checkbox is on and off, a radio/toggle set has one thing on at a time, a drop-down selects one thing at a time, a list lets you select one or more, a slider slides and has a range...all of these elements have commonly-agreed-upon conventions that make software easier to use.

    It is bad design to change these conventions rather than working within them. Seriously: What "style" do you gain by having no selection rather than a "none" selection? Little; Versus the confusion users can face. Why do you need to have only one tower selected but sometimes no tower selected? That would confuse me as it makes no sense. RTS/towerdefense games have either "build mode" or they have you select a tower and then build it in immediate mode. I am assuming that, were I playing your game, you would always display the little thing that says whether or not you can build the current tower here, and that would not go away unless I somehow figured out that your radio buttons can be deselected?

    And how does the user "turn off" the toggle group anyway? Do you have some sort of button that says "no tower"? So have that be the "none" selection instead, or have that be the build-mode toggle. If your idea was to click the selected tower again to un-select it, that's ridiculous and completely non-intuitive: They are not checkboxes. *So many people* would not even think to *try* that, because that is not how such controls work in any other normal application.
     
    rakkarage likes this.
  15. PiMuRho

    PiMuRho

    Joined:
    Jul 11, 2012
    Posts:
    17
    There is definitely a use for having no selection. In my app, I have a quiz element that instantiates a prefab with some text for the question, and 3 toggles with a togglegroup for the possible answers. For each new question, I change the text in the instantiated prefab, but then I have to ungroup the toggles, set them all to off and regroup them. Being able to set the togglegroup to 'none' would be very handy for me.
     
    JoeJoe and ortin like this.
  16. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    @JAKJ While having the ability to deselect a toggle in the group by clicking on it may be counter-intuitive, I see nothing wrong (with few typical use cases listed in this thread) with having "default" state of a group with nothing selected (in fact we already have it and I remember it working that way in every major desktop UI framework I used). So just adding some method like "ClearSelection" to ToggleGroup wouldn't hurt at all.
     
  17. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,244
    And it's already half-way there. Right now a ToggleGroup can start with no active Toggle. It just can't be set to no active Toggle. It should at least be consistent.
     
  18. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    Although I would like this feature.

    http://en.m.wikipedia.org/wiki/Radio_button

     
  19. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,244
    Touché.
     
    rdzavoronok likes this.
  20. Aurecon_Unity

    Aurecon_Unity

    Joined:
    Jul 6, 2011
    Posts:
    241
    I'm going to have to go and respectfully disagree with you on this.

    There are many use cases where it might be preferable to toggle a group to 'off' - there's 6 examples just in this thread (including mine). It's not for you to say whether it's a good or bad design choice - it's about offering the choice to the user in the first place.

    All the default UI actions you describe above can be achieved with the old GUI system. So why update it? Because of new features, ease of use, in the name of progress, and a whole bunch of other important stuff. How about Unity start breaking down the old 'commonly-agreed-upon conventions' to push the UI system in new and exciting ways? I can't really see how it could negatively affect you if the toggle group has a 'toggle to off' option - if you don't need the feature, don't use it. And the people that do need the feature, will use it and be happy.

    I'll again point out that uGUI's biggest competitor has implemented this feature, so clearly people have requested it, and the author has respected those requests. If Unity wants to draw people away from NGUI, then they at least better have feature parity, if not more.
     
    lermy3d likes this.
  21. clever

    clever

    Joined:
    Oct 11, 2012
    Posts:
    37
    I'm someone irked by some people who just want to prevent others from having the flexibility to allow toggle group buttons to all be unchecked! Evidently, a lot of people (including myself) need this functionality, and it would be something you can turn on or off... so why in the world would some people get all sematic on us I don't understand! Let's have the extra functionality and if anything we're all the better for it!
     
    User340 likes this.
  22. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    2,979
    How about if they add a property isRadioButton onto ToggleGroup. Turn it on to make it behave like radio buttons (as JAKJ insists) and turn it off to make it the other way.
     
    clever likes this.
  23. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    2,960
    Listen up, you no-select hating, forced-choice-peddling fascists!

    Unity is a game engine. Games have some odd requirements occasionally, especially in the GUI department. You do things you simply don't do in a spreadsheet app (except for EVE). Let me give an example where a toggle group with zero selections is useful:

    Let's say you have a row of mutually exclusive shield powers. Fire shield, frost shield, physical shield etc. Each costs mana to keep running, so you'd want the option to toggle it off so you can recover a bit, right? Replace the shields with plasma shield/electrical shield and mana with battery if you prefer mechs.
     
    rdzavoronok and User340 like this.
  24. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,852
    We'll look into this.
     
  25. Aurecon_Unity

    Aurecon_Unity

    Joined:
    Jul 6, 2011
    Posts:
    241
    So this has been implemented into beta 21, which is awesome, however I have found a bug with the ToggleGroup...

    Basically if you SetActive(false) a gameobject with a Toggle, it clears the 'Group' to none.

    You can test this yourself by creating a new scene with a few toggles added and a toggle group. Uncheck one of the toggles and you will see that the 'Group' value instantly changes to none.

    I guess I'll have to wait a few more weeks for beta 22 to see this resolved? Bit of a bugger... Nevertheless, thanks for listening to our requests and adding this functionality, Unity.

    EDIT: I forgot that 21 is currently an unstable build - it would be great for this to be fixed for the stable 21 build!
     
    nhf75 likes this.
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,488
    The ToggleGroup value on a Toggle gets null every time a script is being recompiled. Case #641585.
     
    donaldwheaton and nhf75 like this.
  27. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,852
    Thanks for reporting this. This has been fixed for the next release.
     
    lermy3d likes this.
  28. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Hello runevision! Is there any chance that we could have a 'allowMultipleSelection' this would allow us to control not only if the toggle group can be turned off but if the user can have multiple choices selected and if it is allowed that at least one toggle in the group remains active, super useful feature!

    Please consider it!
    Best regards,
    Lermy
     
    Last edited: Aug 27, 2015
  29. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,852
    The toggle group is specifically for ensuring only one option at a time is on (optionally zero can be allowed too). If you want to allow multiple toggle to be on, toggle group is not the right choice for this since it goes against its very purpose.
     
  30. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Could you please point me out what component is the "right choice" for validating that at least on toggle in a group is marked while having multiple choices selected?

    Let me give an example for this kind of context, let's say you have an item collection and you got to the point where you have so many items that you need a filter for them, you can have many filters and those filters can be 'grouped' into categories. So for instance let's say that you are watching your weapon inventory, but you only want to see weapons that cause shadow and light damage, you just go to the damage type filter an uncheck the rest.

    Without this 'allowMultipleSelection' field I have to create the ToggleGroup entire behavior just to validate that this group of filters have at least one toggle active always, since there is nothing useful for the user to do with an empty list.

    Also if I could inherit from ToggleGroup I would have made a CustomToggleGroup myself and there would be no reason for this conversation, but in unity's ToggleGroup implementation the fields and methods are not declared protected or virtual respectively, so I have to desperately ask you for this feature. It would have been as simple as adding this to line 28:

    if(allowMultipleSelection)
    return;

    I cannot see how starting this option inactive in the ToggleGroup could possibly "goes against its very purpose".

    As mickyg said before: "How about Unity start breaking down the old 'commonly-agreed-upon conventions' to push the UI system in new and exciting ways?"
     
    Last edited: Aug 29, 2015
  31. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Hello runevision, you might want to check out this request, there are 22 people following that thread.

    Have a nice one.
    Lermy
     
  32. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Hi again runevision, I found in the ToggleGroup documentation that somehow the guy that programmed the ToggleGroup also considered useful to include a function called 'ActiveToggles' which "Returns the toggles in this group that are active."

    But my question is how can it be a list of active toggles if there is no way of having Multiple Toggle Selection?
     
    Last edited: Aug 29, 2015
  33. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,788
  34. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Totally! However I don't know how would make me feel enjoying my own custom Toggle alone when other people are also yearning for this feature, but at least I am not blind to the need of others... so, since I feel part of this community as soon as I implement it I will share it.
     
  35. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,852
    There isn't currently any. Just like there aren't components to enable or disable some toggles based on values of other toggles, no way to specify fields that have to be filled out, etc. etc. The UI system does not include a comprehensive library of UI widgets and functions; only the most critical commonly used. This is because the UI Team has quite limited resources, and there are other more fundamental problems it needs to focus on which are not as easily handled by custom user scripts.

    When the UI Team is not doing everything that everybody wants, it's because they can't do everything at once. Currently, just getting bugs fixed and improving stability and quality is the first priority.
     
    Kiwasi likes this.
  36. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,852
    Good question! It looks like old API from an earlier design slipped through without being noticed. At an early point we called the state of a toggle for "active", but we later changed it to "on" to avoid confusion with the active state of GameObjects. The ActiveToggles must date back to earlier designs where we still used other terminology and the design was a bit different as well.

    I note that you're linking to the Unity 4.6.2 documentation and that the method is not present in the latest version of the docs, though I'm not sure if the same is the case in the actual API or not. I'll forward it to the UI Team.
     
    Last edited: Sep 1, 2015
  37. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Thank you for reminding us a thing we already knew. There are even coolest features already implemented as pull request and you guys at UI haven't even bother with those.

    Do not worry I am not going to waste more of your time for 2 lines of code, though, you are right, there are plenty of bugs already.
     
    Last edited: Sep 2, 2015
  38. dbkef

    dbkef

    Joined:
    Jun 2, 2015
    Posts:
    1
    Do you really think is better to remove the method 'ActiveToggles' that adding a variable that makes this work for all people that are needing this?
     
    lermy3d likes this.
  39. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Do not worry dbkef, I got you covered, for those who actually need this you can check this link I posted a package containing the corresponding scripts to achieve this with those 2 lines added.

    Enjoy!
    Lermy
     
unityunity