Every button in the UI causes an infinite loop

Greetings!

As the title suggests - literally every button in the UI of my project causes an infinite loop. Or, at least, the engine says so. At first I thought it was just the “Save Settings” button, but couldn’t figure it out. Then I removed it and it still said that one of the checkboxes causes an infinite loop. I have no idea why this is happening. Am I doing something wrong or is the engine bugged? I’m linking the widget code below:

Blueprint for the settings window

UPDATE: I was able to narrow it down to the interface event, but I still have no idea what the cause might be.

So, on widget X change, you call OnChangeTheme, which in turn changes widget X, which in turns calls OnChangeTheme, which in turn …

Can you see the problem?

Okay, so I was able to figure it out.

There is a loop generated by the interface event, allright. It is not immediately obvious, but if you think about it, you’ll quickly find out why it’s happening. When first initialising the widget, it casts to the game instance to retrieve the most recent values of the variables it needs. This changes the values in the spin boxes, which triggers all the OnValueChanged events, which in turn trigger the OnChangeTheme event, which starts this whole process again. This keeps happening forever.

To make it worse, in my instance blueprint I have a ForEachLoop, which is triggered by the OnChangeTheme event… So you have two infinite loops at once (every time the latter event is triggered, an instance of the former loop starts).

In order to fix this, I not only separated the events, which trigger the changes, I also added a DoOnce node before the ForEachLoop in the game instance blueprint, which only gets reset by the Completed pin on the loop. Lastly, I changed the events in the widget from OnValueChanged to OnValueComitted to further prevent the events from basically triggering themselves.

Yep, I managed to figure it out. Check my answer below for the details.