For each loop Array Index bug?

I have this basic setup at the beginning of my blueprint to get the first and the second component in the blueprint. Setup this way so i can just copy and paste it into different blueprints without having to change any variables.

I was raking my brain for hours why it wouldnt work as expected until i started checking every single step. Turns out this setup wasn’t working as i expected. I compared the array index to 1, so the first loop should result in a false cause it would start with 0, so that would be my first component.

Printing out the Array Index, it turns out the loop starts from the top. It prints out 1 then 0.
Adding more components confirms this, starting from 2.
So it’s flipping my list upside down, making the first component in my list, the last component in the Array.

Is it supposed to work this way? I find this very unintuitive.

it’s flipping my list upside down

It’s probably not the loop itself but the Get Children Components node that returns an array ordered in a fashion you would not expect. Just print the comp names in the loop - see what order you get.


When I gave it a quick test, it seems to work fine but something tells me this order is not reliable. As in, I wouldn’t trust that node to return:

image

This very order. I might be wrong.

1 Like

Yeah, that might be it. Gotta look out for this in the future i guess.

image

image

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