Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Toggle OnValueChanged Parameter Doesn't Change

Discussion in 'Unity UI & TextMesh Pro' started by kromenak, Sep 12, 2014.

  1. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    224
    I'm trying to create a simple option toggle with the Toggle component. When I hook up a callback for OnValueChanged and run the game, I noticed that the callback always receives whatever value I set in the Toggle window in the inspector - either true or false?

    public void OnToggle(bool selected)
    {
    Debug.Log(selected);
    }

    Isn't the callback supposed to pass the current value of the toggle itself, not a constant boolean value?
     
  2. _Daniel_

    _Daniel_

    Joined:
    Feb 28, 2007
    Posts:
    2,614
    Make sure you select the method located under the "Dynamic bool" header.
     
  3. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    224
    Ah, that'll do it! Don't know how I managed to miss that. Thanks!
     
  4. mix773

    mix773

    Joined:
    Oct 7, 2014
    Posts:
    2
    Got the same unobvious problem, thanks for time saved!
     
  5. tolosaoldfan

    tolosaoldfan

    Joined:
    Sep 14, 2012
    Posts:
    58
    Thanks for the solution, I just discovered the "dynamic" option that displays the function twice. You saved my day
     
    Lohoris2 likes this.
  6. r2digi

    r2digi

    Joined:
    Sep 26, 2013
    Posts:
    23
    OMG i was trying to figure this out for an hour and never noticed there was two sections LOL. thanks so much!
     
    Lohoris2 likes this.
  7. ownself

    ownself

    Joined:
    Mar 18, 2013
    Posts:
    14
    Thanks man
     
  8. Aseemy

    Aseemy

    Joined:
    Aug 22, 2015
    Posts:
    100
    3 years later and your post is still helping noobs like me. Thanks.
     
    _Daniel_ likes this.
  9. Gotama

    Gotama

    Joined:
    Feb 16, 2014
    Posts:
    4
    Wow, I needed some minutes to figure out "where and what" dynamic bool header is.
    Hope this screen can save some minutes to somebody dynamicToggle.png .
     
  10. pev285

    pev285

    Joined:
    Dec 13, 2017
    Posts:
    1
    You saved time for me!
     
  11. stevensrmiller

    stevensrmiller

    Joined:
    Oct 20, 2017
    Posts:
    34
    Still going strong. This thread just rescued me, too.
     
  12. ZealousAppex

    ZealousAppex

    Joined:
    May 3, 2015
    Posts:
    13
    Thank you save me time!
     
  13. rubenpvargas

    rubenpvargas

    Joined:
    Jul 18, 2012
    Posts:
    17
    Thanks a lot!
     
  14. _Daniel_

    _Daniel_

    Joined:
    Feb 28, 2007
    Posts:
    2,614
    If only I got a dollar for every like.
     
  15. wilsont954

    wilsont954

    Joined:
    Mar 13, 2015
    Posts:
    1
    THANK YOU! STILL GOING STRONG!
     
  16. unity_0rI6ANn0PvV9SA

    unity_0rI6ANn0PvV9SA

    Joined:
    Aug 20, 2018
    Posts:
    1
    Woah, can not believe I have missed it as well.
    Many thanks for the help!