Add to my array in a Struct??

Hello!!

I am trying to add to my array in a struct. This struct goes to my save object and it is for the “level”. My goal is to; on gem pick up, add 1 to player variable, handle destruction, and add the gem to an array of “collected gems” that is then saved. Once the map is loaded again the gem actor will be destroyed as it was added to the array and saved. The struct contains another array called doors, that I would like to populate similarly and be used the same way. I am not sure if I am adding the actors to the array incorrectly, or maybe they are not being saved/loaded properly or not. I assume all 3.

Thank you in advance!!

Does the Array in the struct have its Save Game option checked?

Yes both arrays do

Just to make sure you know- actors & objects themselves can’t be saved just by adding them to a savegame. You’ll have to save the relevant data rather than the actors.

Would it be better to set a boolean variable and then save that to handle the “gem” not spawning again after loading the game?

Yes it would. Maybe something like a Vector to Bool map. Or Int to Bool if you have a constant array of the gems. You just need some sort of identifier to tell the gems apart

Would you be able to show me what that looks like?

This is what I have right now, but im not sure what to put before setting members of the struct. I thought “add unique” would fit, but its coming up as none.



Yes:

Call this whenever you collect a gem:
image
It stores the position of that destroyed gem in an array- we’ll use that as an identifier.

When you want to save the game, add the vector array to the save game.
image

Then, when you want to load, this function will destroy all the gems that you’ve listed.


Make absolutely sure that you copy the array from the savegame back into your blueprint after destroying everything. Or before- either’s fine.