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.

Why does the Toggle Group always reset my default value

Discussion in 'Getting Started' started by lord_wayney, May 20, 2019.

  1. lord_wayney

    lord_wayney

    Joined:
    May 13, 2018
    Posts:
    6
    Hi all,

    I recently used a toggle group with three toggles inside a panel. I set the first toggle as the default value by checking the "is On" check box in the inspector, and it worked well. But after I disactived the parent panel and reactived it again, the default value of the toggle group automatically changed to the third one. I could confirm this from the "is On" in the Inspector, and from the real game running scene.

    Is it a feature or bug? My Unity version is 2019 1.0f2. Am I doing something wrong? What is the right way to set the default value to the first toggle?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,118
    When you stop running scene, anything what you set in inspector, gets reset to the point, what was set before running game.

    If you want to store / save component data in inspector, either copy component at runtime, and paste it back when game stopped.
    Or set data in inspector before running game, then run game.

    Remember to save you changes in scene, when you happy. Unity don't save automatically.
     
  3. lord_wayney

    lord_wayney

    Joined:
    May 13, 2018
    Posts:
    6
    Actually I did set the value before running the scene. I can confirm this behaviour from running the scence, and I can confirm from watching the inspector directly without running game too.

    I do not know if you can reproduce this behaviour too as follows, but this is my steps:

    1. Create a panel
    2. Create 3 toggles as children of the panel.
    3. Create a toggle group as child of the panel
    4. Drag the toggle group onto the toggles.
    5. Choose the first toggle and check the "Is On" while leaving the other two's blank.
    6. Back to the panel. Uncheck the box near the panel's name to make it inactive.
    7. Check the box near the panel's name to make it active again.
    8. Now watch the toggles. You will find the third one become "Is On" and the first one's checkbox is blank. Quite puzzles me.
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,118
    Can you post some screenshots?
    You can simply paste them in post.
    Don't need creating hyper links.
     
  5. lord_wayney

    lord_wayney

    Joined:
    May 13, 2018
    Posts:
    6
    Here are the screenshots, showing the 5-8 steps in my last posts
    1.

    2.

    3.

    4.

     

    Attached Files:

    MrLucid72 likes this.
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,118
    Is On is part of the Toggle script isn't it?
    Can you show scrpt?
    Just remember to use code tags
    Using code tags properly.

    Edit:
    Looks like bug too me.

    You can use bug report
    upload_2019-5-20_18-51-56.png
    with instruction to reproduce.
     
    Last edited: May 20, 2019
    grobonom likes this.
  7. PeterDrake

    PeterDrake

    Joined:
    May 22, 2018
    Posts:
    8
    I can verify this behavior.

    I have a related issue that may help whoever is trying to fix this. (Are the debuggers reading this forum or do we have to submit a bug report somewhere?)

    I'm working through the "Toggles and Radio Buttons" tutorial that starts on p. 74 of Smith's "Unity 2018 Cookbook". There is a script that prints a message whenever one of three toggles (Easy, Medium, and Hard) is turned on. The Easy toggle is the one that is set to Is On within Unity.

    When I run the game, I get a message that the Medium button turned on, but nothing changes visually. By adding another print statement, I discovered that the Medium toggles is turning on and then off when the game starts.

    When I exit game mode (having never actually clicked on any of the toggles nor seen any visual activity in the Game window), more spurious On Value Changed events happen: the Medium toggle reports that it has been turned on, then the Hard one.
     
    MrLucid72 likes this.
  8. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    808
    Same bug here
     
  9. SReplyR

    SReplyR

    Joined:
    Jan 4, 2019
    Posts:
    12
    Same behavior here with Unity 2019.1.7

    There must be definitely some bug in there, because moreover when you change the isOn value in Editor Mode, the Editor doesn´t think that has something to new to Save.
     
  10. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    18,366
    Last edited: Jul 14, 2019
    grobonom likes this.
  11. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    887
    This is NOT fixed (or has returned) in Unity 2020.1!

    A
    B == isOn
    C

    Toggle visibility

    A
    B
    C == isOn

    (C was never set isOn)
     
  12. holyfot

    holyfot

    Joined:
    Dec 16, 2016
    Posts:
    42
    Confirmed not fixed in all of the 2019.3's and 2019.4's.
     
    MrLucid72 likes this.
  13. holyfot

    holyfot

    Joined:
    Dec 16, 2016
    Posts:
    42
    MrLucid72 likes this.
  14. holyfot

    holyfot

    Joined:
    Dec 16, 2016
    Posts:
    42
    I have updated the script: cleaned up warnings, fixed a selecting bug.
     
  15. Trungdv

    Trungdv

    Joined:
    Dec 1, 2012
    Posts:
    22
    This bug still happened in 2019.4. I couldn't choose the default toggle for my toggle group. Then I downloaded their Toggle scripts and fixed them by myself.
     
  16. binoman

    binoman

    Joined:
    Sep 29, 2016
    Posts:
    13
    Still the same on Unity 2021 LTS