ForEachLoop doesnt work?

Hi all. I’m trying to make a space physics simulation but i’m stuck with this problem. I’ve already tried to change it to
a for loop but it still doesn’t work!

I can’t get whats wrong in here so please can you help me?

Which part of it is not working? Is it looping but not adding force? Is it not looping at all? If you add a breakpoint does Bodys have anything in it? Have you tried attaching some sort of debug info to the Cast Failed pin?

It isnt looping at all. I’ve tried to make it print but it doesn’t show anything

In your blueprint is “Start with Tick Enabled” checked? If it is checked are you doing anything that would make it’s tick no longer enabled? Maybe try calling Set Tick Enabled in your construction script?

I’ve already tried to put a print in the foreach completed pin but it doesn’t show nothing too!

At a glance, you have an off by one error in your loop. Last index should always be length - 1. ForEachLoop would get the results you are looking for.

Add a print string on the LoopBody to make sure that something is happening, if it doesn’t make it to the print string, means your array is empty and has nothing inside of it.

I’ve also put a print before the foreach and it shows.

It isn’t empty. I’ve already checked it while it is running

Yes. It seems that it doesn’t get through the for.

Have you tried adding breakpoints and stepping through what happens?

Does Bodys have anything in it? You should be able to watch that value.

I tried to put a for each in the construction script after i created the array and it doesn’t work too.
Maybe it is something having to do with creating the array.

It does work.

What happens if you just make a for loop that counts up to 10 and just prints something on every iteration?

How did you check what was in your array? Are you sure you haven’t accidentally duplicated a variable and it’s messing up because of that? Is it possible you are using a different array than the one you are checking has values in it?

Don’t assume the default values are the values at runtime. Set a breakpoint and look at the array you are passing into the foreach loop at runtime.

I checked it by seeing the default values in the editor.

Hi! Thanks for trying to help. Here is a screenshot:

What specific steps are you taking to populate your array? Thus far the only viable conclusion is that the array is registering as empty, so your foreachloop is going from 0 to 0, so it isn’t looping because there is nothing in it. If you can, please post a screenshot of what you are doing to populate your array with variables.

It is empty. I don’t know what im doing wrong when i’m populating the array.