Updating save files in new game versions

Hello!

My question is: Is there another better way to do the process below, that I don’t know of?

The game I’m releasing on Steam has some crucial things to be saved so everything functions properly. Things like player progress and game settings are stored in one file.

The problem comes when I need to push an update where I’ve added new features to the game. Let’s say I’ve added player leveling and now I need to not only make additions to the save file but change values based on which version the game is updated from. For example, I’ve added player leveling but have to clear the player’s saved money in the new update.

The solution that I’ve come up with is the following:

I will create a “version manager” in my game that is going to keep track of what was the last launched version of my game, then when an update comes if the game’s version is mismatched with the one saved in the save file, run “patches” that are specific for every update. Every patch from the old version has to be run sequentially until the saved game version matches the newest version.

The patches are custom code written to change things in the save file if a new version is detected. These patches can be stacked, so for example, if the player last launched the game in version 1.2 and the latest update is 1.5, at launch the game will go through 3 patches sequentially to make up for the versions that the game was not launched on.

Here’s how that’s going to look like in the version manager:

Save file game version = V1.2
Game version = V1.5

Patches for versions:
:arrow_down: V1.3: Adds +10 coins to the player’s inventory
:arrow_down: V1.4: Clears the player level
:arrow_down: V1.5: Adds +50 coins to the player’s inventory

So these “patches” will be executed upon game launch allowing me to change things to already existing save files, allowing the users not to lose any progress.

What do you think? Is that a good system for updating things in already existing save files?

1 Like

It’s good to think about this kind of thing.

Something that I think is a much more pressing question, which might not have occurred to you yet, is if you change the ‘shape’ of the savegame, what happens then?

Because the system then tries to load your MySaveGame1.0 into a MySaveGame1.1 shaped thing.

I was worried about that for quite a while, and in fact made separate savegames for all new variables I wanted to add. In fact, is doesn’t matter, and the system ‘serializes’ the variable in the savegame, which means as long as you have the save type of variable with the same name, you should be ok.

But I would advise against change names or types of variables :slight_smile:

I don’t think you religiously need to path from one version to another. It’s quite ok for V1.4 to take precedence over all previous versions, without updates. It really depends on what data needs to be carried over, if any.

1 Like

I’m quite aware that if I were to change the name of an already-existing variable, it’s going to reset it for the users who already have a saved file. When I already have shaped the save file structure in one way, there is no going back from that.

If I were to scrap a feature that is already in the version manager’s patches and the user’s seaves, I would need to work around deleting it entirely, because that has the potential to break something.

I usually won’t consider making every variable a separate file, because while yes it might be a little bit cleaner, it has the same kind of problem, because what happens when you have to reset the player money in one version, but then another add 10 coins to their inventory. Also, it brings the problem where players can just upload and download save files for the different variables, allowing them to easily alter the different variables. While tools like Cheat Engine exist, they may not be as user-friendly as just replacing a file.

In my version manager system, it is quite important to go through every patch sequentially because that’s the only way I’m able to ensure that no matter what the users will get the the same changes as the new users without a save file. (eg. The starting money is changed from 0 to 10. In that case, I will create a patch that will give 10 coins to every existing player)

The only difference is that the new users are just beginning with the default values for the variables, while for the already existing users, I alter the required things in their save file so everyone gets the same experience.

That’s what I’m saying, you can, as long as it’s only adding or removing variables.

I didn’t have a file for each variable, only the new concepts.

1 Like

Okay! Thanks for your time. It was important for me to check how another person would approach this. It was a pleasure talking with you! :grin:

I’ve already made a prototype of that system and think it might work! I tested it with an old save file (The one that the Steam players currently have) where that system doesn’t exist, and I was able to achieve my goal of altering the save file and laying the grounds for better save file management across the future versions. :smile:

1 Like

Hi. I am having a problem and I think its related with something like this.

I made a save file for skins in a shop that when you open the game it will load you coins. The skins you own and the one you have equipped.

Ingame it will show the name of the skin, the price and a little shopping cart if you dont have it. If you do it will show a text that says if you have it equipped or not, with a green tick

Everything seems to work fine

But when I update the game and export it as a new .exe file The new skins I add on that version seems to glitch because when you go to the store it shows the “Equip” text but also the shopping cart and you cant buy them or do anything with them.

I think its related with “saved game files” because when i remove the old save file and re-generate the file the new skins works.

I think it is because I am adding new values in the array that contains all the Info (I have separated arrays) but since the .sav file its older and dosent contain that informations the game glitches.

What can I do to fix this???

1 Like

This is not quite the same issue.

In this case you have to write the game code to cope with both the old and new versions of the save file.

What you have to avoid, is changing the name or types of variables. I don’t think there’s any way back from that.

I would also make sure you have copies of the old save file to work with, make sure your new code works with them as well as the new format.

For instance, you’re talking about having an array of ownership, but are the new items just added to the end? You haven’t change the order of the items you had in the old version, I assume.

Also, I’d recommend this

You can open the save games and take a look at what’s actually in them, rather than trying to debug things in another way… :slight_smile:

Exactly, I just added New values to the array. i didnt change any oder of the values or the name of variable. And the type of variable its still the same.

The only thing I do its just add new slots and add new code inside the Widget to set the correct values based on the game instance.

But since the save game file just overrides any value. the values that doesnt exists on the old .sav are just ignored but they are not left with the default values I set in the editor.

I do have 2 .sav files, the old and the new.

Btw how do I make the code be able to work with old and new save files? I actually dont really understand what do you mean with that.

If you need images of the code tell me.

Btw thanks for answering that quick. :slight_smile:

1 Like

This might be it. It could be your save code. It should have the form

1 Read save game
2 Update some parts
3 Write it back out

It sounds a bit like your code only does 3?

You can have just one actually .sav file, but the format may change over time ( adding variables etc ).

I think My code only does those 3 things.

This is what I did in the code.

  1. Check if a save file exist. If it doesnt, create a new one with the name ShopData.sav
  2. Next, The game its an Online multiplayer so the game only saves when you go back to the menu after playing an online match and everytime you leave the shop or buy something.
  3. When the game is re-started the values from the Save files are loaded and applied in the game instance using the “init” event.

That is what I coded.

All my save files variables are just arrays and I set each skin to a number on the array.

Basically in the array I have 10 elements and each one represents a skin.

And to check if you own a skin the element will be set to true.

Example: If you The skin with the ID set to 5. Then That means in this array the element 5 its set to true.

The new 3 elements (8, 9 and 10) are the ones that are giving me issues.

1 Like

Can you make it happen in single player? Do you have copies of the old .sav that you can experiment with?

Well the game supports both single and multiplayer. But when you save the game Its always offline.

I also do have a old .sav file

1 Like

Right. So you should be able to read the old .sav, update this array and save to the new format. It should work.

I would really recommend that plugin. You can find out right away if it’s your coding or it’s something wrong in the save game :slight_smile:

Okay I will try. But how do I do that?

Is there anything that I have to change on the code??

1 Like

Just like normal, you can read the save file and write it back out. But you know that it has changed ( in format ).

Sorry but I dont get what do you mean, or what am I suppoused to do inside the engine :sweat_smile: :sweat_smile: :sweat_smile:

1 Like

The engine will be able to read the old file format, after you update the array, it will write the .sav in the new format. It’s automatic.

What don’t you understand? :slight_smile:

You need to be able to look at the save file to see what’s going wrong. You can either do that with A LOT of print strings, or you can get a copy of that plug in.

Take a look at the old save file, then run your code and take a look at the new save file. Did it work? If the save file looks ok, then your code is making an assumption that is not correct. It could be either.

Yeah I know its supoussed to be automatic. I just putted the old .sav file from the older version. but I still got the same problem. I think the file didnt update.

1 Like

Here

Its supoussed to look like this image.

But instead i got this:

That is the problem.

But when I remove the old .sav file it creates a new one and it works and looks like the first image.

I opened the Files with the notepad and I can see there are more lines of information and data in the right Image. Wich is the New updated save file that I generated

But this file its empty and I have to do it manually.

I think I wasnt clear enough.

1 Like