Download

Infinite Loop in Timer? (How am I supposed to use these...)

I’d like a timer to call a function (not an event, contrary to this blueprint) in code based on a couple of parameters, at a set interval. I’m actually trying to implement this in C++ but it’s giving me a headache, so I thought I’d try Blueprint first. The following code in Blueprint is giving me an infinite loop error? I know the timer is calling itself at the start of the loop, but it’s based on an IF statement that can change, so surely this is broken? How am I supposed to correctly do the following?

The idea is that I want a function to instantly call the ‘SpawnActor’ function when the fire button is pressed, then repeat this at a given interval until we’ve spawned the correct amount of them. NOT using a delay because they’re not available to me in C++.

dc3c01ba3f092f078d73412f98e5f86d61aa59a1.jpeg

Hi
try this , by putting Set timer after you call fire function
OnBeginOverlap->Fire->SetTimer(with looping checked)
and you should add a boolean to check if the event is called (overlap or pressing button) to not see the timer each time this one is called cause this will reset your timer each time

it should work in c++ too

Nvm, got it working in C++ so all is well :stuck_out_tongue:

It’s strange that Timers in Blueprints that are setup like this cause Infinite Loop errors, whereas ones done in C++ don’t… I think the Infinite Loop checker might be a bit too vigilant.

I guess a timer is supposed to call a function and not to act like a delay.

To get your BP working put the spawn actor note into a function “doFire” and call that function from the timer.

it’s not strange , fire->setTimer(fire)->fire->…

I did that originally and it still didn’t work, gave me the same infinite loop error, so I tried to use the Custom Event and it’s still the same issue.

I don’t think Blueprint timers allow you to call the same function or event they were fired from, whereas in code they do and it works fine (that’s how they’re used in ShooterGame).

to keep your bp logic and avoid this infinite loop

the condition have to be if(salvo counter==0)->true->SetTimer(with looping checked)
->false->if(salvo counter== salvo count)->clear timer