The issue of the infinite loop arose when I tried to use code to swap between these camera settings instead of clicking on the toggles manually. When a battle begins, we open with an overview of the battlefield by having both generals in the frame. Next, we move to the player’s preparation phase where they lock in some decisions. Then the enemy’s preparation phase which attempts to counter the player. For each phase, the camera needs to focus on the respective general.

Easy enough, right? I called FollowPlayer() or FollowEnemy() from my BattleManager.cs script and everything worked fine, but the buttons in the toggle group weren’t reflecting the change in camera focus. It would just stay selected on whatever the default was.

Honestly, this is totally fine and could be how it ends up working anyway because the player shouldn’t have control over the camera during this phase, but I was determined to make it work for debugging purposes.

Just throw a Toggle.IsOn = true in each camera method, right? It seems so per the Unity docs, but that’s because the example isn’t dealing with a toggle group. Through much Googling (as you do) I found when you use Toggle.IsOn = true for toggles in a toggle group, it fires off Toggle.IsOn = false for the others. However, the method you’ve assigned to fire OnValueChanged will fire wether the toggle is turned on or off—it only cares that the variable changes.

So now your program is stuck flipping switches on and off forever and ever, amen. ☠️🔥

This makes sense, but also kind of doesn’t. Why doesn’t it get stuck in the same loop when clicking the button vs. enabling it programmatically? Honestly, I’ve no idea. But after banging my head against the wall trying all kinds of hacky fixes for this issue the intellisense in Visual Basic revealed something that sounded like exactly what I was looking for: SetIsOnWithoutNotify.

Lo and behold, it was exactly what I was looking for.

The difference with this method is that it won’t trigger the OnValueChanged for any of the toggles involved resulting in a purely-UI update. Since the functionality is already contained in the methods, that’s all I was looking for. The resulting code just adds a single line to each camera focus method: