0
\$\begingroup\$

I currently have a crude save system in my game.

When my game is first launched after download, it checks for three directories in a certain location on the client computer, user://save1, user://save2, and users://save3.

If these directories don't exist, they are created with some empty files player_data.save, level_data.save, persistence_data.save and meta_data.save.

Then, at periodic points in my game, these files are updated. (Which base directory is used depends on which save slot the player chose when they selected a new game, or loaded.)

I have read a lot about the importance of versioning to protect compatibility with saves (for example, here and here).

So, how I can implement versioning into this save system to protect myself from incompatibilities when I inevitably release updates and patches to the game?

For example, is it advisable to create different save directories per game version, so that on boot you check if you have a save directory corresponding to your current game version? Or is it advisable to just have a single save directory and merely save a text file with the version number in the sub directories?

A structure like:

version_1_saves
    save1
    save2
    save3

version_2_saves
    save1
    save2
    save3

Or a structure like:

saves
    save1
        version.txt
    save2
        version.txt
    save3
        version.txt

And what do the checks look like when you do release an update and need to check for compatibility when a player boots the game or tries to load an old save?

\$\endgroup\$
  • \$\begingroup\$ Just to be clear, are you also trying to have your savegames generated with a new game version compatible with your older game versions? \$\endgroup\$ – Vaillancourt Jul 29 at 16:13
  • 2
    \$\begingroup\$ @AlexandreVaillancourt, hadn't really considered that, but I guess that's not so important to me. The most important thing is for old saves to be compatible with new game version. \$\endgroup\$ – GoldenGremlin Jul 29 at 22:42
4
\$\begingroup\$

You could add a version number to your savegame file format itself. The savegame loader loads the savegame file as plain data, checks the version number which it expects in a specific position and then passes the data to the correct loading/upgrading strategy for parsing.

This, of course, means that you are no longer able to change your savegame format in a way which would break the version number detection. But that should not be an issue if you have that information relatively close to the start of the file.

\$\endgroup\$
  • 1
    \$\begingroup\$ If writing your own formatter, typically the format version comes absolute-first, or is key-value paired in some manner (eg json). Both work. \$\endgroup\$ – Draco18s Jul 30 at 14:47
1
\$\begingroup\$

The last example is the best way.

Pros

  • There will only be 3 saves max.
  • Easily read what version the save is.

Cons

  • It will use unnecessary space on your player's system.
  • Has to parse the file name to get the version number.

I would just create a json file that you can read into your save system to get the correct version files. Json file can store created date or even computer that was created on so you can verify that the user didn't download a save from someone else.

If the save file is from another version you could make changes that match with the latest version of the game/save file. Such as enemy1 doesn't exist in the game anymore.

Example:

If saveFile.version < 1.1.1 {
 //Remove enemy1 from save
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.