Alexei Osipov
Alexei Osipov

Reputation: 761

How to repair RenPy game save loading after renaming pickled python class?

There is a RenPy-based game that uses custom Python classes for some game objects. Recently we renamed some modules and classes as part of refactoring. This broke loading of old game saves because Pickle can't find classes.

The Pickle itself supports a mechanism to properly handle situation with class renaming: https://wiki.python.org/moin/UsingPickle/RenamingModules

However I can't apply this code to a RenPy game because save/load process is controlled by RenPy in it's loadsave.py module. Is there a way to fix loading without patching RenPy code? Any monkeypatch ideas?

Upvotes: 0

Views: 1993

Answers (1)

renpytom
renpytom

Reputation: 26

What I usually do when I move stuff around in Ren'Py is to just create an alias from the old name of the class to the new name. That's enough for pickle - it looks up the old name, and creates a class with the new name.

For example, if I had

class OldClass(object):
    pass

and wanted to rename it to NewClass, I would have the code:

class NewClass(object):
    pass

OldClass = NewClass

This works across modules, too.

Upvotes: 1

Related Questions