Toggle OnValueChanged Parameter Doesn't Change

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?

5 Likes

Make sure you select the method located under the “Dynamic bool” header.

55 Likes

Ah, that’ll do it! Don’t know how I managed to miss that. Thanks!

2 Likes

Got the same unobvious problem, thanks for time saved!

Thanks for the solution, I just discovered the “dynamic” option that displays the function twice. You saved my day

2 Likes

OMG i was trying to figure this out for an hour and never noticed there was two sections LOL. thanks so much!

1 Like

Thanks man

3 years later and your post is still helping noobs like me. Thanks.

2 Likes

Wow, I needed some minutes to figure out “where and what” dynamic bool header is.
Hope this screen can save some minutes to somebody3242671--249332--dynamicToggle.png .

23 Likes

You saved time for me!

1 Like

Still going strong. This thread just rescued me, too.

Thank you save me time!

Thanks a lot!

If only I got a dollar for every like.

THANK YOU! STILL GOING STRONG!

Woah, can not believe I have missed it as well.
Many thanks for the help!

Old thread but still saved me, who worked with Unity for 5 years but didn’t know there’s a dynamic functions can be used in Toggle…

Hey, got anything for sale on the Asset Store?

Me too - FIVE years later.

Can someone confirm that it actually works?
I have a simple toggle button that calls on the event “OnValueChanged” a call a GameObject.SetActive in dynamic mode and it doesn’t work. If I use the static mode it does work.
Unity 2019.3.0f6

Edit: It won’t work if fast play mode is enabled. It has to go through the normal full Domain/Scene etc reload when hitting play.

2 Likes