ForLoop - How to run the loop from the last element to the first?

I’m trying to implement the Fisher-Yates shuffle algorithm in Blueprints. However, the default ForLoop is completely skipping the “Loop Body” section of the function since (I’m assuming) the first index is larger than the last index, and the ForLoop is trying to increase the First Index by 1

What’s the best way for me to solve this?

Hey Nylira,

Thanks for your question! We are looking at implementing a built-in solution to allow ForLoops to more easily increment or decrement between the First and Last Index values but, in the meantime, for your setup you can use a node setup like this:

Hope this helps!

-Steve

4 Likes

Thanks! Helps a ton.

How could I do this with a ForEachLoop?

Was the reverse loop implemented in UE 4.16? I can’t find it.