Keeping old save files working after scene changes

Some node names and paths changed during development and now older saves break because they still point to the old structure. So now how to keep saves compatible when scenes get updated?

Write a save version in your save files, and don’t rely on implicit paths.

If your save file starts with a number you can increase it as you update the game, if you find a lower number than expected you can reject the save file or try to migrate the data.

2 Likes

I’d recommend taking a look at why you’re saving node names and paths in your save game files at all. Those are design decisions that are going to continue to cause you problems in the future. @gertkeno 's suggestion is a great one for dealing with your current problem.

A better long-term solution would be to make sure that you save everything in a Dictionary, and when you need complexity, a Dictionary of Dictionaries. This is what JSON is, and it’s why it is the defacto data transfer protocol for web programming. The benefit for backwards/forwards compatibility being that new data gets ignored by older versions, and newer versions can handle adding default data when older versions don’t contain it. Which then means you never have to deal with this problem again.

If you really need to store references to paths (or node names), you can do so by utilizing UIDs. They don’t change if the node name or node path change.

If node paths change, how do you handle old ones? Mapping them or avoiding paths entirely?

If i skip saving node paths how should i rebuild objects??

Depending on which version of Godot you are using you could use UID instead of node paths. Also there is a method of using @export or right clicking the node and using ‘Access as Unique Name’ depending on how you need to use it.

To access UID’s you have to right click the scene/resource in the FileSystem tab of the editor and then copy UID

If you are accessing specific computer files I would recommend reading these:

For older saves you might need to make new code just to handle and convert them if your userbase is big enough or just release an announcement that old saves won’t work anymore and if they want to play them they have to use an older version

Fantastic question.

I create two methods for complex objects: to_dictionary() and from_dictionary(). For me, this started with trying to send complex objects by RPC call for multiplayer. But it works equally well for serializing objects for saving and loading.

If you say use @export to add a PackedScene, you can store the UID as a String, and then load it using that same UID.

I replied to an older thread on a similar topic. Linking here as it might contain some additional useful info for you (it also might not!)

1 Like