Dear Dear All,
I have been trying to get some basic understanding of all the blueprint nodes, but when trying to use the ForEachLoop i encounter a problem. In the blueprint i try to get one object named fadsf* to move to 5 different locations with a delay between the movement, those vectors are contained in the array named ArrayTest which is declared in the character blueprint “char”. I added a print node to see whether the loop actually moves the fadsf* actor, however when running there is a delay of 3 seconds, as intended, however after that the object fadsf* directly moves to the last vector of the array and only the last location is printed on the screen. I can’t find where it is going wrong so could you please help me.
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.