ForEachloop only iterating last element

So I have an answer for you, but it’s not one you’re going to want to hear.

ForEachLoop struggles mightily with the delay node. In fact, I’d say it’s unusable and completely broken. I can’t confirm this is the same with ForLoop, but I definitely JUST experienced this in 4.11 with the ForEach. That said, there are two workarounds, neither of which is incredibly fun.

You can create your own Loop function by modifying a duplicate of the original. I don’t know all the technicals behind it, but the last tutorial I saw on it seemed straightforward enough… Pull a couple execution pins around and drop in a node or two and you’re done. Just google “custom foreachloop unreal” and I’m sure you’ll get some hits.

The other way, which I used because it gave me more control over what the loop was doing, was to create a custom ForEachLoop in the event graph itself using Timer By Event. Basically, you fire this guy off and every n seconds it will fire again. n would be your delay in this case. Then you need a Branch or two to use as cutoff conditions for the loop to check when it’s finished. Let me see if I can dig up our usage case to show you. It was for a treasure chest that loops through possible rewards before displaying the reward it gives you, ala Nazi Zombies’ Mystery Box.

It should be noted we are also using a delay later in the loop, which is probably redundant. But if you do need one inside the loop like this, make sure it’s set to the same as your timer or you’ll get some really odd results. I’m sure this particular blueprint needs refactoring and cleaning up at the moment (just prototyped a couple days ago), but this should give you an idea of the workaround.