ForEach Loop losing data in array

I have an issue where when I try to use a for each loop, the information in the array I call the loop on, disappears. I have checked that the data is in the array. See GIF for example. (The values turn to null as soon as it’s accessed)

251332-unrealproblem-2.gif

I have also posted a picture of how I add values to the array. It just an event that I call from another BP. alt text

Any Suggestions? I’m still kinda new to unreal, but I don’t fully know why this is happening. I had also tried using sets, and that also didn’t work.

Thank you for any and all help.

Does the second print string ever fire? Also what is before all of this in the flow of execution?

Your screenshots are not informative enough. All I can see is the ForEach Loop prints your string N times depending on the array length. What happens to the array elements is unclear.

Why do you think something gets lost? What happens to the array elements - maybe there are some further conditions in the execution sequence?

If you could provide more detailed screenshots that would be helpful.

The Second string never fires, before this is just a lot of code to get an actor that is the attach parent’s parent.I will post more details.

See that’s just it, the array never gets printed. It only prints the first string, but not the second. I don’t understand why the references get lost, seeing I don’t clear them anywhere.

You must be clearing the array somehow. Does the completed pin fire? Sometimes blueprint nodes are just “bad” deleting the non-working ones and replacing them sometimes fixes problems that have no other explanation. Also try printing a string for the array length just prior to the loop and see if it has anything in it.

Added some additional Screenshots. Warning, it is a mess.

This is a majority of the BP. But I’m just trying to figure out why the “for each” isn’t running

Umm…I just took a couple minutes to try and figure out that appropriately named “mess” of blueprint you have there and I am sorry I have no clue what you are trying to do. But after looking at this, I can tell you with 100% certainty the least of your issues is why the “For Each Loop” isn’t firing. You are running a million things off tick…one of which is the “For Each Loop”, I can’t think of any situation (maybe there is 1 out there but I doubt this is it) where you would want a “For Each Loop” to run on tick, that is pretty absurd. You have kind of mitigated that effect somewhat by using a ton of “Do Once” nodes with resets all over the place that I can’t really follow.You also have a bunch of booleans regulating flow through this massive thing here but I can only see where one of those booleans is being “set” which makes it even harder to follow exactly what you are trying to accomplish. My advice, write down, step by step the “GOAL/MECHANIC” desired at the end of all of this and we will work on re-doing this entire set-up because I don’t think this is something you should event attempt to salvage in its current state.

So I just tested printing the string length. If you look at the Top of the 1st new screenshot. I added a print string before the branch (After posting the screenshot). And it prints the length. But if it’s after the branch, it prints 0.

Solved…
In the setting of the array, I needed to set “Instance Editable” to be true.
Sigh…
Thank you all for your help.

Thank you, I’m sorry that you had to try to read it. I’m trying to emulate a motor, and this is just a wire end. I’m still super new to unreal programming, but thank you for helping me.
I did just solve it, it was a simple checkbox in the setting of the variable.

1st screenshot, bottom center. Shouldn’t that ADD node be hooked up to AttachToActor?

I mean I am glad you fixed it, BUT I caution you, that set-up is bound to give you problems down the line. In general “tick + loop” is never a good idea. I would switch this over to “events, timers, functions etc”. Tick is a heavy node to use for something like this and probably only needs to be used for smooth motion where you really do need to update the location of an object every frame.

Thank you, Events are a place that I struggle with, so I will take your advice on my next project. I would try to change things if I didn’t have a week left on this 3-month project. Thank you again!