Scene Plugin key in use

Hi guys, I’m having a problem using a plugin.

I’m using vue with phaser 3 and it’s working fine.
So I have 2 routes: Home and Map.

For the first time, when I go from Home to Map, the plugin load my map and I have no problem.

But if I back to Home, and click again in Map, I get this message:

PluginManager.js?98fe:361 Scene Plugin key in use: KineticScrollingPlugin

Here is my Map.vue

<template>
  <div>
    <div id="game-container"></div>
  </div>
</template>

<script>
import Phaser from "phaser";
import KineticScrolling from "./KineticScrolling";
import BootScene from "./BootScene";
import PlayScene from "./PlayScene";

export default {
  name: "TileMap",

destroyed() {
  window.game.destroy(true);
},

mounted() {
  window.game = new Phaser.Game({
    type: Phaser.AUTO,
    width: window.innerWidth,
    height: window.innerHeight - 70,
    parent: "game-container",
    scene: [BootScene, PlayScene],
    plugins: {
      scene: [{
        key: "KineticScrollingPlugin",
        plugin: KineticScrolling,
        mapping: "kineticScrolling"
      }]
     }
    });
  }
};
</script>

And here is my plygin:

import * as Phaser from "phaser";

export default class KineticScroll extends Phaser.Plugins.ScenePlugin {
  constructor(scene, pluginManager) {
    super(scene, pluginManager);
  }
}

I’m not sure what’s is going on… anybody knows how to fix it?

Thanks :slight_smile:

I get that too when hot reloading.

My work around to this was in my PlayScene create a destroy function:

destroy() {
  this.plugins.removeScenePlugin("KineticScrollingPlugin");
}

Then in my beforeDestroy (Vue)

beforeDestroy() {
  window.game.scene.getScene("PlayScene").destroy();
  window.game.destroy(true);
}

And everything works great :wink:

Reviving this thread to see if anyone has a better solution for this now. I’m in a similar situation where I’m running the game within a React single-page-app, and if I switch tabs and come back to the game, when it re-renders I get this error.

I’ll potentially have multiple plugins in multiple scenes, so constantly adding lines to a beforeDestroy() function sounds kind of crummy. Anyone have a good solution for plugin management?

If you’re destroying the game, you should remove any plugins then.

Or avoid destroying the game.