MZ Dot Move System error: "Cannot read property 'massCharacters' of undefined"

Hello! So I have been using the Dot Move System plugin for pixel movement in my game, and it's been working almost perfectly for everything I need. But now I've discovered a strange error that I just can't seem to solve.

So for context, my game requires a custom menu for saving and loading, so I have been using the script call (from here) for loading the game, rather than loading through the default load scene:

Code:
DataManager.loadGame(1)
  .then(() => {
    SoundManager.playLoad();
    SceneManager._scene.fadeOutAll();
    if ($gameSystem.versionId() !== $dataSystem.versionId) {
      const p = $gamePlayer;
      p.reserveTransfer($gameMap.mapId(), p.x, p.y, p.direction(), 0);
      p.requestMapReload();
    }
    SceneManager.goto(Scene_Map);
    $gameSystem.onAfterLoad();
  }).catch(() => SoundManager.playBuzzer());

When I try to load the game this way though, I get an error from the Dot Move System plugin.

19.PNG
20.PNG


And the strange part is that it doesn't give me this error when I try loading the game through the SceneManager.push(Scene_Load); method. It loads the game perfectly fine that way. But I can't use this method if I want to maintain the custom menus I've created.

For the sake of eliminating other points of conflict, I've tested this all in a new blank project, with the Dot Move System as the only active plugin.

Would anyone possibly know why this is happening? I had believed that the script should do essentially the same thing as selecting a file from the load scene, so I am unsure why the error only occurs when using the script call. Is there something I need to add to it so that it produces the same result as loading from the load scene?
First guess would be that you're trying to load an incompatible savefile.

Adding or removing a plugin that modifies the savefile to store its own data will always make all older savefiles incompatible.
You can test this by starting a new game, saving that and then loading the new savefile, that should work.

after that the key to the error is "of undefined" - you're trying to access a data object that does not exist. This can happen with savefiles that were made before the new dataobject was added, or it could be because a plugin is configured wrong and has a reference to something that does not exist.
First guess would be that you're trying to load an incompatible savefile.

Adding or removing a plugin that modifies the savefile to store its own data will always make all older savefiles incompatible.
You can test this by starting a new game, saving that and then loading the new savefile, that should work.

after that the key to the error is "of undefined" - you're trying to access a data object that does not exist. This can happen with savefiles that were made before the new dataobject was added, or it could be because a plugin is configured wrong and has a reference to something that does not exist.

Hi, thanks for the reply!

Unfortunately, this error occurs with brand new save files as well. And it happens regardless of whether I save using a save script or save through the default save menu. It'll save just fine, and then it'll only load properly through the load scene or through the "continue" menu, but not through the script call. It's a very confusing situation, haha.
then show us a screenshot of the event that uses the script call, perhaps we can see what you did wrong.
The error means $gameTemp.mapCharactersCache() is returning undefined. Looks like that value would typically be initialised via Scene_Map#start, but clearly that's not happening soon enough. 😴

I'll check back when I have more time, but my guess is that it may be related to order of operations vs the scene change. SceneManager.goto just assigns the next scene and marks the current one as inactive: the scene doesn't change immediately. The core scripts have checks like SceneManager.isSceneChanging() at critical points, maybe the plugin just doesn't account for loading mid-update.

Maybe try adding these lines to the script call, immediately after $gameSystem.onAfterLoad()?
JavaScript:
  $gameTemp.initCharacterTempDatas();
  $gameMap.initMapCharactersCache();
The error means $gameTemp.mapCharactersCache() is returning undefined. Looks like that value would typically be initialised via Scene_Map#start, but clearly that's not happening soon enough. 😴

I'll check back when I have more time, but my guess is that it may be related to order of operations vs the scene change. SceneManager.goto just assigns the next scene and marks the current one as inactive: the scene doesn't change immediately. The core scripts have checks like SceneManager.isSceneChanging() at critical points, maybe the plugin just doesn't account for loading mid-update.

Maybe try adding these lines to the script call, immediately after $gameSystem.onAfterLoad()?
JavaScript:
  $gameTemp.initCharacterTempDatas();
  $gameMap.initMapCharactersCache();

Ahh, yes, that fixed it!! It works perfectly now! Thank you so much! =)
Oh wow, I didn't think that would be enough to fix it. 😊

Hopefully you don't run into any more problems with it. Happy RPG Making!

Edit:

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/dot-move-system-error-cannot-read-property-masscharacters-of-undefined.156187/