Page 1 of 1

Get save version from SavedGameData

Posted: Thu Aug 29, 2024 6:04 am
by zebialowicz.s
Hi !
Im curious, is that any option to get a version number from save data without deserializing all the saves ?
Our game supports up to 99 slots for saves, each can have ~50mb data inside, which means that checking every version number once player will open loading panel is not an option, that would gives us some seconds lag every time player will open loading panel.
We have to prevent save trading, or changing names of saves because game does not support backward compatibility.
SavedGamaData has a field with version, so we can use it, but we are not sure if that's doable to read that value without deserializing all the data.

Best !

Re: Get save version from SavedGameData

Posted: Thu Aug 29, 2024 9:01 am
by Tony Li
Hi,

Two options:

Option 1: If you're using PlayerPrefsSavedGameDataStorer or DiskSavedGameDataStorer and you don't tick the Encrypt option, then the saved game file/string will always start with:

Code: Select all

{"m_version":7,
where "7" in this case is the version number. You can just open the file/string and read up to the first comma.


Option 2: Make your own subclass of SavedGameDataStorer that stores the version separately. For example, it could be a subclass of DiskSavedGameDataStorer that stores an int and then the saved game data string. Or your class could store each saved game file's version number in the filename or in a separate "catalog" file.