While loop infinite loop

I’m using a while loop, but am getting an infinite loop error when it’s called in game. I understand why it’s giving an error, even if it’s not an infinite loop in the end, but can’t find a workaround to get through the error. I need to have a loop that only triggers every 1 minute in game and can’t find a good solution without the branch after the loop, which causes the error.

I realize I forgot to show the condition, but all it’s doing is seeing if sleep is <= 100, and at the end, it’s adding .2 to sleep

it’s hard to tell whats going on without seeing the rest of the blueprint, but if you want something on a 1 minute timer, you could try using the ‘delay’ node or the ‘add timeline’ node.

If those wont work, then take a bigger screenshot of the rest of your blueprint and we can try to help

There isn’t too much more to see, but hope it helps. To clarify, the game time array is getting the in game minutes, and I’m trying to only trigger the set sleep when one minute in game has gone by.

And the in game minutes are not related to real world time, and can be adjusted to go by faster or slower, so no delays can be used.

You’re setting the “Temp Time” to equal your “Game Time 1”, then you’re asking it if it’s equal, which it will always be equal after the first loop because you set it as equal. So it just keep looping because the “Sleep” variable never gets incremented.

Try connecting that empty “true” pin to your “Set Sleep” node and see if that fixes it.

It does fix it, but that defeats the purpose of having the branch. The reason I set temp time to equal game time, is because game time constantly updates, so I only want the branch to fire once game time updates. Sleep should get incremented every 1 in game minute, but the in game loop detection sees it the way you do, and doesn’t consider game time updating, thus causing the error. I just need a way to fix the loop, while only updating sleep every 1 in game minute.

oh i see. You’re not understanding how arrays work. This “Game Time” array doesn’t tell your blueprint when to update, it’s just a bunch of numbers that you pull from. Those white lines that connect all the nodes are what tell it when to update. The way you have it set up, your loop is executing on every “tick”. If your framerate is 60fps, then this event fires 60 times per second, in real time, no matter how often you update that array.

If you know the ratio of real seconds to in-game seconds, you could just add a delay node and set that ratio as the delay time. So if your ratio was 2 in-game seconds for 1 real second, you would put 0.5 as the duration, then get rid of the array stuff, like this:

If I connect both true and false to the sleep variable, it sets sleep to 100 nearly instantaneously, and I want to avoid that.