Variables set in struct are changed when retrieved from an array

Hello everyone, silly question here

I made an array of structures with each structure having two interger variables.
Then i get two int variables with “Random Int from Range” and make them into a struct that i add into the array :


But as soon as i try to retrieve them through “For Each Loop”, their previously set int variables have changed :

I tried to create two custom int variable to freeze the output of “Random Int from Range” because i thought maybe i was missing an insight of how this node is working.
I know this might sound like a basic issue but after hours of debugging and trying things, im still stuck.

Cheers !

Hi @Archkeeper1,

Can you tell me more about how you’re reading the initial values of the two integers?


If it’s something like this - where you’re printing out the values by hooking up the make struct to a print statement - it’ll have the bugged behavior you described.

That’s because all attached “pure” nodes - the ones that don’t have the white execution line - will fire off each time a node with the white execution line runs.


So when PrintString runs here, all of these nodes will also run.


Then when the Add function fires afterwards, all these nodes will run again - resulting in a different struct being added to the array than the one that was printed out.



If you’d like another way to view what’s in your data structure, you can try a breakpoint. Press F9 on your add node, and start your game. When that node runs, the program will pause, and you can hover over the data to see what’s in it. Then you can check to see if that’s what’s coming out when you later loop through your data structure.


Or, if you’d like to use a print string method, simply store the value into a variable as soon as its created, and then reference that variable instead of the “Make BPS_RoomStruct” node


I’m not sure this is the problem you’re running into, but its behavior sounds like it fits what you’re seeing, and it can be a pretty unintuitive stumbling block if you haven’t heard about it.

Hope this helps!