ForLoop runs once and never completes

Ok, so I’m probably doing something wierd
But I’ve never had this happen before so I’m posting this here in case anyone else has ever encountered this

So in the blueprint above, a simple for loop is run and it’s getting the stack size off an object, which in this case is 11.

I’ve setup the prints to see if the value changes before, while or after the ForLoop. ( It doesn’t. )
Instead it prints out 11 TWICE…Once when the loop is executed and once in the LoopBody.

The complete print is never executed and it certainly does not complete 11 loops, rather it appears to execute ONE and then never finish. The ForLoop is not altered in any way.

This is certainly very strange behaviour and something I haven’t encountered before. It’s probably something very simple that I’ve ignored. But posting in case someone has any similar experiences.

Thanks.

What happens after the print in the loop body? Are you hitting a return node?

From the image you posted, seems like you’re doing this in a Macro, and connecting the loop body to the Output.

If you connect the loop “Completed” to the Output of your Macro instead (and leave the loop body disconnected from the Output), your loop will run 11 times.

Best to show the whole BP. The print in the loop body will always show the same because that variable is outside the loop.

This looks likely…

This, judging by the image that was briefly shown and then removed taking my elaborate comment down with it :expressionless: Serves me well for being wordy.

This is true, but I didn’t expect the variable to change after the loop. I expected it to print out 11, 11 times. And then print it out once more when the Completed was executed. But this never happens.

This is more or less it, in the loop body it loops through an array of item references ( items that are near the player ) and it checks if any of them matches the item structure, if they do we destroy the item and then run a function which subtracts the ItemStack by 1. If not we simply subtract the ItemStack by one without destroying anything. The copy of the structure is so that the loop runs 11 times and no half that because the value is being subtracted.

Sorry, didn’t expect to get a reply so soon, figured I’d reiterate my wording. :V
I did see your reply in email however, if only part of it.

You were right. Good eye there.
I didn’t even think about how the macro gets terminated after hitting the output. I’ve been doing some of these loops recently where i needed the output to be triggered the amount of times of the item in the stack, but not in this instance.

I’d mark you as an answer, but yours is only a reply. So all I can do is thumb you up, and thank you.

Thank you, completed forgot that I terminated after the macro was run and didn’t require the output to match the stack size in this instance.