Download

ForEachLoop is not acting properly

A while back, I created a shop interface using UMG. It worked dynamically through s struct array. I set up a ForEachLoop to create a button for each item in the struct array. It worked perfectly in that project.

However, recently, I tried to create an identical system in a new project, and while it does add the buttons for each item in the array, it is creating each button as the same button (in the 0 index). I used the exact same code as I had used the first time, yet this time it is working differently. Any help?

Here is the original project, using the exact same code as above. As you can see, it worked on this one.

Once again, this code is IDENTICAL to the working code, so I have no idea why it is doing this. The array currently has two items. The first (0 index) is 5 x 5 room. The second item (index 1) is 6 x 6 room.

Did you verify that the ForEachLoop iterates over different elements by e.g. adding a PrintString node in the LoopBody and printint any kind of variable in the current struct?

Can you show all related nodes in your UMGStoreButton widget please?

I had not tried the print string in the Loop Body. Once I did, I discovered the issue. I had been running the bindings for the button’s info off the same struct array variable that I referenced in the code. I needed to run it through the local variable instead. Once I did that, it worked perfectly. The buttons WERE populating properly. It was the bindings on the button that were the issue. Thanks for the tip on the print string in the loop body. I had run one off of the Completed pin already, but not in the body itself.