Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    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:
    219
    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,561
    Make sure you select the method located under the "Dynamic bool" header.
     
  3. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    219
    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:
    56
    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:
    25
    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!