MZ Issue loading a game that has a new type of object

So I developed a rune system for my game where each rune is an instance of the object Game_Rune. I store all runes in an array inside Game_Party, like this:

JavaScript:
ZNT.Game_Party_initialize = Game_Party.prototype.initialize
Game_Party.prototype.initialize = function() {
    ZNT.Game_Party_initialize.call(this);
    this._runes = []
}

Game_Party.prototype.addRune = function(runeId) {
    if (this.hasRune(runeId))
        return 0;
    this._runes.push( new Game_Rune(runeId) );
}


When I save my game, this is how my Game_Rune object looks like. By this point, everything works fine, I can call any methods from my Game_Rune object and it all runs perfectly.

JavaScript:
Game_Rune {_runeId: 1, level: 1, _skills: Array(1), experience: 0}


However, after loading my saved game, this is how my Game_Rune object looks like. From this point on, nothing works. I can't call any of the Game_Rune methods anymore, because I get a "not a method" exception... It looks like the object loaded isn't a Game_Rune, but something else, like a generic object.

JavaScript:
{_runeId: 1, level: 1, _skills: Array(1), experience: 0, @: "Game_Rune"}

Is there any way to fix this problem? I have no idea what's happening 🙁
You didn't really show us any of the relevant code (such as the definition of the Game_Rune class and the methods that you're talking about, or the code that is specifically triggering the error), so it's kinda hard to tell you exactly what's happening. If you don't actually show us the code, then there's not much we can do to help you debug it.

If I were to take a stab in the dark, based on your description of the issue, it sounds like you're maybe trying to attach methods to the individual objects, instead of to the class itself. Methods don't get preserved when an object is serialized into JSON, so any methods that you've directly attached to the objects won't persist through game saves.

*edit* caethyril's explanation makes more sense.
MV/MZ include specific encode/decode methods for preserving custom prototypes (Game_Actor, Game_Item, etc) through saves.

Make sure Game_Rune is declared as a global; if not, JsonEx._decode (rmmz_core.js) will not correctly reassign the prototype on parse.
Make sure Game_Rune is declared as a global; if not, JsonEx._decode (rmmz_core.js) will not correctly reassign the prototype on parse.
Yeah! Doing this solved my problem! I had the following code stored in a function, but when I put it outside the function, saving and loading objects of this type started to work! Thank you so much! 😀

JavaScript:
function Game_Rune() {
    this.initialize(...arguments);
}

Original thread: https://forums.rpgmakerweb.com/threads/issue-loading-a-game-that-has-a-new-type-of-object.156289/