For loop only loop once

Here, I want to apply damage to all of enemy which is overlap with box but when I connect “apply damage” to “loop body”, it only loop once even if the length of overlap actors is 2 or more. When I do not connect “apply damage” it can run properly. What is the reason? Thank you very much!

In this picture, kill one enemy can get 20 points and there is only one text appearing.


overlap 3, damage twice.

If you put a print string after the apply damage,how many hello show up?

2


if there are 3 enemy, still print twice.

this looks weird,I have no idea then :joy:

:joy:

Create an Event in the BP Enemy class (TakeDamage). Call this Event in the Loop.
Have TakeDamage apply the damage.
Pass everything to the Event you need to technically apply the damage.
Damage, PlayerController, Self

1 Like

Pure functions (like GetOverlappingActors) will get executed for every pin connected to them, and under the hood, the for loop will get expanded, effectively calling the connected function on every loop, which will not give you the result that you want

Save the result of GetOverlappingActors to a temporary variable, and loop on that variable instead

2 Likes

Thank you, problem is done. My understanding: Get Overlapping Actors is a pure function that is called again at each iteration of the loop. Right?

Thank you, the key point has been mentioned. I think the key is that Get Overlapping Actors is a pure function that is called again at each iteration of the loop.

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