Infinite loop detected

Hello. I try to make cinematic in UE4. One fine moment, I need the camera focus to track the character every tick during the animation, and then turn it off. If I use enable tick, then an infinite loop occurs. If you use a simple delay of 0.2, then it is noticeable that the camera does not always keep up with the character. If you set the delay to less than 0.2, then again there is an infinite loop. How to solve it?

In BP there is a protection from infinite loops, and as far as I know if a loop did too much iteration in seconds - system thinks it’s infinite loop.
I can suggest you to bind a function on looping timer with very small delay and condition check to stop. For example (made in UE5 but still suitable for UE4):

Just in case: this BP won’t be working correctly if executes on Tick event.

Your code is an infinite loop. You can see it go back to the switch node, and because the boolean variable hasn’t changed, it will just take the same path again.
You need to make the execution output of “Focus to Fem” either just stop flowing (not be connected,) or flow to the same node as the “true” output of the switch goes, depending on what additional behavior you want.

Here it turns out like this. The character starts to play the animation, and at that moment the camera focuses on it. Since the character is moving, the camera must keep track of the focal length every tick. The camera then asks for the blueprint of the Fem(ale) character - have you finished the animation? If not, then the camera continues to track the focus, if so, the camera moves the focus to another character. Therefore, we need a local cycle, and for each tick.

Another possible solution if logic is on Tick event: just remove this loop, set rotaton of camera at every tick, but change focus depends on condition.
I mean: Tick event, pin connects to branch and, depends on condition: (condition failed - animation still plays) move to logic to set camera focus and no more logic or move to another logic if condition true (animation ends). This logic will calls every tick, which means Tick event calls as fast as engine can (usually - very small delay) - you don’t need extra loop inside.

You do not need that local cycle. The On Tick function will be called every tick, so you ask the character for the focal distance every tick.
If you just loop back, the code will just keep running the loop, doing nothing else, which is where the “infinite loop” comes in.

I tried using your timer and I can say that it works well. At least better than it was, but still the focus of the camera is sometimes lost, even if you set the time in SetTimerByEvent to 0.001. It’s possible that it’s something else. Maybe in the camera shutter settings or something else.



I must try further.

Didn’t find what On Tick Function is. Maybe you mean Event Tick?

Yes, On Tick is a Event Tick in BP.

I don’t think solution with timer will works in Event Tick. If you need to use this event - just remove loop, because this event still will be called every tick.

Post your own code , engine code will not help and post the whole blueprint containing the code, … also tell me are you using for loop or not?


I tried to use a loop with break, it also gives an infinite loop error.

Post the image in two parts and zoom it to be cleared enaugh to see.
There everything is blured and hard to see what are you doing.

Yes, beacuse you built an infinite loop.

Things that need to happen with a delay, should generally either be handled with a Timer (most efficient, typically,) or by polling and updating state inside Tick.
Game logic, in general, is much more like a state machine, than like a straight-line set of lines of code.

1 Like

I have new problem. Camera mesh offset.
I’ll be back here later.

I decided to try another way. Move focus tracking to Event Tick. Then, by entering a Switch node, switch camera focus tracking between characters.

However, this doesn’t work. For some reason, the Switch node does not allow tracking of the camera focus on the character.

If you disable the Switch node.


That all works great.

Why the Switch node does not work, and how to get around it?