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:

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?

1 Answer

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest