I don't understand how this is an infinite loop.

Yes, the potential for an infinite loop is there, but there is a break condition (this is programming 101) and, even if it’s stuck in this loop (as if the media player stops, so the condition is never met), then really, so what? It doesn’t kill processing, uses the DelayUntilNextTick (which would be no different than using OnTick, but is much cleaner, IMO).

I understand why they catch this, but I feel like it’s invalid in this case, I should be able to run this.

For the record, if you’re wondering what’s going on, Bink media player sucks, and I’m trying to, at the end, loop back to a specific point (infinitely… unless an external trigger stops it by settting “Repeat” to false).

Infinite loop errors can be encountered even if there isn’t an infinite recursion going on due to the max iteration limit. You can adjust the Max Loop Iteration Count setting from your project settings but that won’t be any use in this case, because you cannot add delays inside while loops like this. There are actually ways to add delays after loops such as while or for but if your objective is to call a function every X seconds, you can simply use timers! To do that, just place a Set Timer by Event node, plug it into your execution chain while making sure it gets executed only once each time you want the loop to begin, check that tickbox inside the node that says Loop, then drag out of it’s red square pin, release it on an empty space, type in “Custom Event” to place a custom event node, and call your function after the custom event. When the conditions you’ve set are met to stop the loop, get a Clear and Invalidate Timer by Handle node, connect it’s blue input pin to the Return Value pin of the timer and execute that node.

Hope this helps! :innocent:

IMO move your code to tick and don’t use while and delay.

Loop macros and delays don’t work well together in BP.

the break condition must be in the loop body.

I see what you tried to do here. But: Delay is an async task. Or, to be precise, a node that creates an async task object, that somewhen later will trigger its Completed pin. That’s the problem: the node itself only create task and itself immediately returns breaking execution flow.

And since your body doesn’t change anything, that means that you infinitely spawns Delay until next tick tasks.

As for solution - as others said, there are better ways to do it, like timers or tick()

2 Likes