Problems with save UE4

Hello! I’m a beginner in Unreal Engine 4 and game development in general. I’m working on a card game and have a level called DeckBuilder and a MainMenu. In DeckBuilder, the main widget, CardStuck, contains the deck editor and a list of saved decks.

My problem is that when I press Escape in the DeckBuilder level, the list of decks is not saved. However, when I switch from this level to the main menu (a separate level) and then back to DeckBuilder, the list of decks is preserved.

In my GameInstance, I check if a save exists (Save1), and if it does, I load it into the variable CardGameSave; otherwise, I create an empty save and assign it to CardGameSave.

In the CardStuck widget, on EventConstruct, I do the following: get the GameInstance → cast to CardGameInst → retrieve CardGameSave from it, get the list of decks from there, and add them to a scroll box.

Again, when I change levels, everything is saved in the scroll box if I pressed the “Save Deck” button. When that button is pressed, I do: get GameInstance → cast to CardGameInst → get CardGameSave → get the list of decks (array), add a new deck to it → then save game to slot (I might not remember the exact name or link correctly) and also call an event Save Game in GameInstance that performs the same save operation.

In my level blueprint, on Event End Play, I call Event Save Game in GameInstance. Additionally, on Event Destruct of the CardStuck widget, I also trigger Save Game.

Perhaps the issue lies with complex data structures that I’m trying to save, but I’m not entirely sure.

Could you please help me identify what might be causing this problem? Thank you!

1 Like

It’s pretty much impossible to tell, without seeing the code. I know you’ve given some pseudo code. In this thread

I laid out an easy way to do the SG, as a lot of people get this wrong.

Hope that helps.