RegisterToggle nonfunctional?

My apologize if this is a known issue – I’ll be happy to report it if not.

I tried to use RegisterToggle on a ToggleGroup component in script to add prefabs w/ Toggle to the group. However, it appeared to do nothing. When I instead used the group field on the Toggle component to assign the ToggleGroup, it works fine. Am I using RegisterToggle wrong somehow?

Hi there,

I have the exact same issue. The “group” Toggle field works ok though.

Actually, I looked into the Toggle code, and it seems the RegisterToggle method is called internally by the toggle, base on its group assignment.

private void SetToggleGroup(ToggleGroup newGroup, bool setMemberValue)
{
ToggleGroup oldGroup = m_Group;

// Sometimes IsActive returns false in OnDisable so don’t check for it.
// Rather remove the toggle too oftem than too little.
if (m_Group != null)
m_Group.UnregisterToggle(this);

// At runtime the group variable should be set but not when calling this method from OnEnable or OnDisable.
// That’s why we use the setMemberValue parameter.
if (setMemberValue)
m_Group = newGroup;

// Only register to the new group if this Toggle is active.
if (m_Group != null && IsActive())
m_Group.RegisterToggle(this);

// If we are in a new group, and this toggle is on, notify group.
// Note: Don’t refer to m_Group here as it’s not guaranteed to have been set.
if (newGroup != null && newGroup != oldGroup && isOn && IsActive())
m_Group.NotifyToggleOn(this);
}