How do you handle game updates and existing saves?

Hi all -

I use JSON serialization to save and load saved character data (as an instance of Attributes.cs file, which includes basic things like health, damage, experience, etc.). I also use JSON to store relevant game logic data, such as the upgrades that the user has purchased and their level. Importantly, each upgrade is an instance of the GeneralUpgrade.cs class that; these upgrades are then saved as a List(). Whenever the user purchases an upgrade, the GlobalUpgrade(int index) method checks the value of the upgrade in the list with that index and handles the purchase processing, including deducting the upgrade’s cost and incrementing its level.

The problem, of course, is that this approach does not handle all that well instances where the list size changes between the time the game is saved and the time it is loaded (for example, when I implement another upgrade as part of a new game version). It either throws a argument out of range error or simply refers to the list in the original save game (both make sense, really).

My question is, how do YOU handle updates to game versions? Right now, my game basically relies on running Start() and then loading whatever was saved - to me, it seems that something needs to happen to the data after it’s been loaded to bring it up to date with the game version.

For example, I could expand my list of upgrades to 99 by filling it with placeholders, and then simply replace the placeholder with an actual upgrade whenever one needs to be added after the game is loaded. Similarly, whenever I need to change an existing upgrade, I can simply write it through a post-load script (for example, if game version is less than what it should be, change this upgrade to that, etc). However, wouldn’t that force me to basically apply all future updates as a patch to the core version of the game rather than modifying the core itself - or is this how it’s normally done anyway? It seems that, after 10-15 updates, I’d end up with a monster patch file that basically incorporates all the changes made in the last 10-15 versions? Seems clumsy, but maybe that’s how it’s actually done?

Another option seems to be to handle it via cloud integration by having all the current upgrade stored in the back-end and retrieved whenever the game is loaded - but that might be a tad too complicated for my needs.

I don’t really understand everything you’re saying. If you save information about which items the user has purchased then how does adding more items to the game cause a problem?

I’ve done something similar before in our Top Gear game. The player purchased cars. Each car has an id. The saved information is a list of ids (containing only those owned by the player). Adding more cars (with new ids) to the game does not affect the saved list of ids.

1 Like

Thanks, Andy!

Even though I wasn’t clear in my original post, your feedback helped me understand what the issue was. Specifically, where you save only the purchased items in a list, I save all my items in a list.

So, presumably, when you load the game, any new items that you’ve added since the last upgrade are, by definition, not in the list of purchased ones and therefore can’t possibly give you any headache. Whereas, in my case, when I load a game after having added some new items, I need to find a way to seamlessly integrate them into an existing list.

Upon reflection, there is no compelling reason to do things my way (except for the simplicity of editing list items in the Inspector) - so let me rewrite the code and see what I can do here.

Exactly.