ForEachLoop doesn't iterate all items

Ran into this and here is what I made out from my experience.

Answer:
Here is how I resolved the issue. I made a variable of Object type, Array checked. I then set this from the “Get Children Components” and Pass that variable to the “ForEachLoop” this way the array is unaffected by the “Simulate Physics”

I had an array of 8 children when the loop starts. Printing the index out it goes to 3 (0-3 4 runs), half of the array. So it appears that the “Set Simulate Physics” must remove the object as a child. Which makes sense because a parent constraint connection would cause any transformation to the parent to alter the children. This explains the half-ish run of the loop (rounded up: 9 children = 5 loops). At index 0 it removes the item at 0 and the original index 1 moves to index 0. So when it goes to process the object at index 1 this is now the original index 2 object.

Example:

–Children Of Component–

0 = “Dog”

1 = “Cat”

2 = “Donkey”

3 = “Monkey”

4 = “Ape”

5 = “Turtle”

As it runs it would look like

– Start Index 0 –

0 = “Dog”

1 = “Cat”

2 = “Donkey”

3 = “Monkey”

4 = “Ape”

5 = “Turtle”

– After Loop 0 –

0 = “Cat”

1 = “Donkey”

2 = “Monkey”

3 = “Ape”

4 = “Turtle”

– Start Index 1 –

0 = “Cat”

1 = “Donkey”

2 = “Monkey”

3 = “Ape”

4 = “Turtle”

– After Loop 1 –

0 = “Cat”

1 = “Monkey”

2 = “Ape”

3 = “Turtle”

– Start Index 2 –

0 = “Cat”

1 = “Monkey”

2 = “Ape”

3 = “Turtle”

– After Loop 2 –

0 = “Cat”

1 = “Monkey”

2 = “Turtle”

Notice Cat, Monkey and Turtle are never processed by the loop, because they took the place of just processed index locations.

2 Likes