I have a simple script which changes the color of the selected Toggle in a Toggle Group.
They call this function through the built-in “On Value Changed” function, passing in themselves as a parameter:
public void OnSelectionChanged(GameObject me)
{
Toggle meToggle = me.GetComponent<Toggle>();
if (meToggle.isOn)
{
var colors = meToggle.colors;
colors.normalColor = Color.blue;
meToggle.colors = colors;
} else
{
var colors = meToggle.colors;
colors.normalColor = Color.white;
meToggle.colors = colors;
}
}
The problem is the highlight is not shown until a mouse click, a keyboard input etc. is done.
The function is indeed firing twice, first for the unchecked box and second for the checked one.
The “isOn” is indeed being set correctly.