Toggle onValueChanged Called When Other Button is Clicked

I see that onValueChanged is called whenever a button’s isOn state changes, even if that happens when another toggle in the group is clicked. Anytime one toggle button in a group is clicked, onValueChanged is called for that button, and also for the previously-selected button when its isOn state changes to false. Is there any way to make these toggles respond ONLY when their isOn state changes to true, as toggle buttons commonly work? Having more than one button function called when just one button is clicked really complicates things.

You could probably get what you need by using an EventTrigger in the Toggle you care about, and that way you would be testing for the mouse interacting with the object rather than the object’s value changing.

Caveat: haven’t tried it personally.

A mouseClick trigger does the trick. Thanks. Seems like this should be the default behavior. I’ve never had a case where I wanted a radio button to do something when another member of its group is selected. I never noticed this before, but in this case the buttons start an animation, and two animations at the same time interfered with each other.

1 Like

Awesome, good to know.

I disagree: the event is called OnValueChanged, right? The value did change, just as an emergent property of the group “only one alive at a time,” that’s all.

You could do your own check to make sure you disregard the turn OFF too, and only handle the ON

Right. I think the default event should be OnPointerClick rather than OnValueChange. IME, that’s the way I’ve always coded radio buttons.

1 Like