Getting infinite loop issues but I know it'll eventually finish

I have a timer function running throughout the game and at times I want to speed this up (eg when sleeping). Everything is working fine except when using a while loop to check if the target time has been reached yet or not at which point I get an infinite loop error. I know that this will finish once the world time reaches the target time but Unreal doesn’t. BP below:


The first timer changes the timer to the faster speed, the second returns it to the default.

I’ve seen that I can override this by changing the max iterations, but it has got me wondering if there’s a more elegant solution to this problem. One thought I had was to have the event tick constantly check if the condition has been met or not and trigger custom events to change the timer’s times but I try to avoid using event tick where I can.

Anyone any thoughts?

Seems you do have an infinite loop. In Blueprints a WhileLoop runs in the same frame. Timers/Delays don’t tick while in the loop, so the condition never changes triggering max-iteration error.

Imo the condition should be after a branch where the first timer is executed.

2 Likes

You can extend the allowed number of loops before a loop is consider infinite somewhere in the engine preferences but won’t solve you issue and it will slow down your compile.

That being said I can’t possibly imagine why would you need a loop to check a timer. As @pezzott1 noted, the loop is executed in a single frame which means the timer is the same through the whole execution. And the loop is of course infinite in that case.

Maybe you can explain what you are trying to achieve with those timers so we can help clean up your BP and get rid of the loop altogether.

1 Like