custom $gameObjects loading without prototype data

Hey folks,

Running into an issue with saving and loading custom game objects that I've replicated in a new project.


I define my custom game object (inheriting from existing game objects):


function Game_TroopABS() {
this.initialize.apply(this, arguments);
}

Game_TroopABS.prototype = Object.create(Game_Unit.prototype);
Game_TroopABS.prototype.constructor = Game_TroopABS;

Game_TroopABS.prototype.initialize = function() {
Game_Unit.prototype.initialize.call(this);
};​



To actualize this game object in the game, I alias DataManager.createGameObjects:

var alias_DataManager_createGameObjects = DataManager.createGameObjects;
DataManager.createGameObjects = function() {
alias_DataManager_createGameObjects.call(this);
$gameTroopABS = new Game_TroopABS();
};​


To save this game object:

var alias_DataManager_makeSaveContents = DataManager.makeSaveContents;
DataManager.makeSaveContents = function() {
var contents = alias_DataManager_makeSaveContents.call(this);
contents.troopABS = $gameTroopABS;
return contents;
};​


Then to load the game object:

var alias_DataManager_extractSaveContents = DataManager.extractSaveContents;
DataManager.extractSaveContents = function(contents) {
alias_DataManager_extractSaveContents.call(this, contents);
$gameTroopABS = contents.troopABS;
};​

On first run, I can use $gameTroopABS and it's prototypal Game_Troop functions.
When I load a save file, calls to $gameTroopABS Game_Troop functions throw undefined errors.

When I console.log(contents.troopABS) within DataManager.makeSaveContents, I get a Game_TroopABS object. I feel confident $gameTroopABS data is being stored as a Game_TroopABS object.

When I console.log($gameTroopABS) within DataManager.extractSaveContents, I just get an Object with no prototype data, just its immediate properties.
This is not true for console.log($gameParty/$gamePlayer/etc.) and it seems to me that I am saving them and loading them just the same.


What am I missing about this process?

Original thread: https://forums.rpgmakerweb.com/threads/custom-gameobjects-loading-without-prototype-data.87450/