Save and load game not working in packaged game

Hi, I’m making a tab target RPG using blueprints and have created a slot save system where you can interact with an actor to load a save widget to the viewport with three slots. When you click a slot it saves the game, including all the player variables, location, inventory, quests, learnt skills etc.

This system works perfectly when played in the editor, you can save to any of the three slots, exit to either the start menu or PC and then load up one of the save files flawlessly when restarting the game. But as soon as I package the game up and test it, it no longer works!

I can see that a .sav file is created within the applocal file and there is data within it but it doesn’t load correctly in game. Interestingly, after a lot of testing, I’ve realised that the save does work correctly if you save the game, exit the game, then load it up again, start a new game and resave over that original save. As soon as you save to one of the other empty slots though, the game no longer loads any of the saves correctly.

It’s almost like the game can’t save a fresh .sav file without there being an existing one from a previous session.

For reference, the save functionality is done via a function in the player character that is executed when a save slot is clicked in the save widget. Likewise for the load functionality, which is executed after the player begin play code executes. I’ve tried moving the code to the game mode, as well as installing a save plug-in from the store but still encounter the same issue!

I’ve been stuck with this problem for the last few months and I’m at a loss as to what to do to fix it as searching the web for answers provides no solution. Hopefully one of you will be able to help with my issue. I’m happy to share screenshots of the code if that helps. Thanks!

Yo pensando rápido el error es cuando utilizas otro slot, porque no metes todos los datos en una struct y la conviertes en un tipo array y cada slot de tu UMG es un id

Thanks for the response! I think I understand, so rather than copying out all the variables individually to the save game class, I should copy them to a structure which is then added to an array for the 3 slots and then save that array instead?

1 Like

Siiii

I have tried saving the variables via a structure, which works in editor, but I still seem to be getting the same issue of the save/load not working when testing in the packaged game.

I’ve also just tried moving the save and load functionality to the game instance but am still getting the same result when testing in the packaged build. I really don’t understand why it doesn’t save correctly without there being an existing save file from a previous session for it to save over :weary:

Hey there @Jw0ody!

I think you’re at a point where you’re going to have to share code screenshots! Saving/loading can be complicated so it would help if we had some visual representation :slight_smile:

No problem at all!

So to save/load game the player clicks on one of the three slots in the save load widget, they can only save the game when in the game world and load when in the main menu. Clicking a slot to either save or load the game does the following:

When you’re in game and saving, clicking a slot button executes the save function via the player character. Here’s how that function starts in the player character:

Following this, all the player character’s variables are then saved:

The save slot then updates with the player’s level, location and time to show that they’ve saved the game and in which you’d then close the save load widget and continue playing.

To then load a game, when you first enter the main menu and press play, the character is loaded into the game world and the same save load widget loads up for the player instantly to either click a slot to load or play a new game (meaning they don’t actually see that they’ve loaded into the game world yet). When clicking a slot the start game event is executed in the player character, which closes the save load widget and loads the player character’s variables (this happens after the begin play code which initializes the UI, inventory actor, quest manager actor etc).

Here’s the player character’s begin play code that loads the save load widget and initializes everything else:

Following this, when loading a game the start game event in the player character is executed by clicking a save slot in the save load widget:

image

This event executes the load game function also in the player character, which is similar to the save game function:

This all works flawlessly when testing in the editor but as soon as I package the game and test the packaged version, it doesn’t seem to save everything correctly. I’ve tried moving the save code to the game mode and game instance and still get the save results when testing.

This is how a save game loads correctly when testing in the editor. As you can see the learnt abilities are saved, including their location of the hotbar, the inventory is saved, your equipment is saved, location, health, mana, level and quests:

But when saving and loading in the packaged build, it loads like this, with only the level, location, gold, health and mana saving. The equipment saves which slots you had equipment in but you cannot seem to unequip it, as if it hasn’t actually respawned your equipment correctly. Similarly the hotbar saves where you had abilities equipped but not the abilities themselves, and the quests do not seem to save at all.

Hopefully all this adds more context to my issue.

You have to load the classes.
You probably have nothing referencing them, so they never load.

On editor a class is loaded when you open the blueprint panel for them so you don’t notice that you should make sure that a class is “hard referenced” to be loaded to memory.

2 Likes

Oh my gosh, thank-you so much! Your response made me realise that I was trying to save several actor variables rather than their classes!

Saving out their classes instead of the actors themselves, and then spawning the actors from these saved classes when loading has fixed my issue!

Thanks again for the help :grin:

would you be so kind as to show what was the problem? cause I don’t get it! how to save classes? my save load function works in the editor but when compiling the save/load slot buttons are just not there! HELP!