Array clearing all data in its items; retains length and content type

I’ve finally narrowed down this bizarre issue to a cause, but now i have no idea how to fix it.
Around 50-60 seconds into runtime, my Backpack and Equipped arrays, which are both full of PickupParent actors, clear all the data of the actors they contain. I know this because testing the length of the array never changes, but if I print the display name of Backpack[0] every frame, eventually it just disappears, signaling that the clearing has happened.

Whether I stand perfectly still or not, or press any inputs, this always happens around 50-60 seconds. What is going on?

Hi Strebicux1,

We’ll need some more info - can you share the backpack code in some snapshots? (you can copy/paste images straight into your posts).

1 Like

Yeah, lemme know if more comments are neccessary

1 Like


I’m wondering if its caused by this array add somehow… but this works perfectly until the array is cleared 50-60 seconds in

Thanks - it’s a bit too blurry though, can you paste in raw/png rather than jpeg?

1 Like


Is this any better? It looks pretty sharp to me but it might change after upload

Yeah still unreadable sorry, can you split it up into smaller areas but larger nodes?

image

1 Like


I highly doubt the problem is in this image but here
also can only put one image per so, another post below


There’s two nearly identical execution chains here, only difference is that the top one adds to Equipped weapons and bottom adds to Backpack items. Both arrays get cleared at the same time.

Thanks for posting those. Is there anywhere else that could potentially modify your PlayerData structure? Can you do a FindAllReferences on it…

1 Like

image
It’s never set anywhere (using defaults), so the only time I can see where it would be changed is the Adds for the two arrays. Is there a better way to add content to an array within a structure?

is this a 100% blueprint or is the array c++ based? If so make sure it’s a UProperty or it will get garbage collected with time.

  • Are you maybe setting this array somewhere to a new value?
  • Are there any places in your code where you call clear on this array?
  • Is the parameter always passed by reference and not copied somewhere clearing the array?
1 Like

I think it must be the “ClosestPickup” - the fact your array still has the correct length is a clue. Is it possible that is getting destroyed?

I tested it here at it works ok with the array side of things:

1 Like

100% blueprint

Interesting, it might be. Only issue I see with this is that I don’t re add the Closest Pickup multiple times. Why would the arrays clear themselves after a period of time if they were working perfectly before? I’ll go add some isValids before the Closest Pickup gets added where needed and see if anything changes


This is what it looks like when its working btw


and this is when its not working

the 8 slots below “EQUIPPED” show up regardless.
the “misc” section on the right is for stuff that doesn’t fit anywhere else

so just to reiterate, they lose all their data and just go into the Misc section because they don’t have any other classification. It seems like they’ve reverted to just a default Object, but I’ll test that in a second. unfortunately, adding more isvalid checks to the ClosestPickup adding did not fix it.

Thanks, that gives more insight.
I just did another test, the only way I’ve been able to reproduce anything close so far is by linking in the Destroy in the code below:

1 Like

Sorry for the late reply, the website has limited my commenting.

After testing what class the items get switched to, I found that its literally an invalid value. As in, their class is just entirely removed? ???

(in response to your last message) What kind of errors does this generate? I don’t see anything that would cause inValidity or surprise removal… but maybe that’s what I’m missing in my project too

Also, I don’t believe any of the other values in the Player Data struct are being altered in any way

If there’s an alternate way to add items to an array within a struct, I want to try that but I can’t think of anything


Here are the details/defaults of the structure

I still can’t help but feel that your ClosestPickup actor is being destroyed - the error I got was just that the array item was null like yours.

You can add items to an array like this too:

To test your arrays are ok, you could try adding an array of strings to your PlayerData Struct, then at the same time as you add the reference to the Closest Pickup, add it’s name like:

image

1 Like