For Each Loop followed by Set Timer by Event have strange behaviour

Hi All,
I am quite new in Unreal but so far I was able to find solutions for my struggles. Unfortunately atm I am stuck. I am trying to run for each loop filled with elements from Multi Sphere Trace For Objects and for each hit I want to set a timer and do some dmg to actor which was hit (like damage over time). But it seems it will just pick one actor (first one?) and do dmg but for rest it does nothing. To make sure there is not error somewhere else I tried to do dmg to the same array without using timer (immediate one time dmg) and it works fine (all actors get dmg) which led me to believe that either I am using timer incorrectly or there is something “wrong” when combining those two nodes. Can you please help?

1 Like

You’re setting the same timer repeatedly.

In fact, not even one timer is running properly, because the execute pin of the for loop, will run this in one frame

But before the timer gets used, the next frame will happen.

If you want a timer for each object, you can make an array of timer handles. What is much easier, is to do this in the blueprint of the hit objects :slight_smile:

Yeah, I just had a quick go, don’t do it :smiley: Arrays of actors and timer handles, and it’s not a good method.

Just have that damage on timer stuff in the actor, and call it for each actor in the for loop.

Maybe this

but still not great :wink:

2 Likes

Heya,

thanks a lot! I tried many different ways but I ended up making it same way as you shown.
Still it is kinda confusing to me why approach of creating in each for each loop timer does not work. I mean I understand your explanation but… :smiley:
From now on - 1 timer and within do stuff on multiple actors :wink:

Thanks again and have a nice day!

It’s because you keep reusing the same timer. You only have one timer there :slight_smile:

Ahhh, yes of course! But… :smiley: I tried to go from each loop (“Spell” BP) to BP component attached to each actor. And on this actor I setup basically the same (timer & damage).
Interestingly what it did was one tick of timer on all Actors which were in the array in “Spell” BP but then it did nothing else…
Anyway - thank you for your valuable answers :wink:

If you make a custom event in each actor, called auto-damage or something, in the for loop on each actor, you can just call the auto-damage event, and they will all run their own timer.

If it seems like a hassle to put the same code in all of them, then it’s time to find out about blueprint inheritance :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.