# Rex Virtual joystick Cannot read properties of undefined (reading ‘get’)

**URL:** <https://phaser.discourse.group/t/rex-virtual-joystick-cannot-read-properties-of-undefined-reading-get/11348>\
**Category:** Phaser 3\
**Created:** [March 4, 2022, 7:51pm UTC](https://phaser.discourse.group/t/rex-virtual-joystick-cannot-read-properties-of-undefined-reading-get/11348 "2022-03-04T19:51:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![stanleyseow](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/stanleyseow/32/1190_2.png) [@stanleyseow](https://phaser.discourse.group/u/stanleyseow)\
**Post date:** [March 4, 2022, 7:51pm UTC](https://phaser.discourse.group/t/rex-virtual-joystick-cannot-read-properties-of-undefined-reading-get/11348/1 "2022-03-04T19:51:03Z")

</div>

I added the following according to the docs

`npm i phaser3-rex-plugins`

`import VirtualJoystick from 'phaser3-rex-plugins/plugins/virtualjoystick.js';`

```javascript
var joystick = scene.plugins.get('rexVirtualJoystick').add(scene, {
    x: 100,
    y: 100,
    //radius: 100,
    //base: baseGameObject,
    //thumb: thumbGameObject,
    // dir: '8dir',
    // forceMin: 16,
    // fixed: true,
    // enable: true
});

```

I got the following errors :

> world.js?5e60:85 Uncaught TypeError: Cannot read properties of undefined (reading ‘get’)  
> at world.create (world.js?5e60:86:1)  
> at SceneManager.create (phaser.js?d4ef:100338:1)  
> at SceneManager.loadComplete (phaser.js?d4ef:100250:1)  
> at LoaderPlugin.emit (phaser.js?d4ef:1908:1)  
> at LoaderPlugin.loadComplete (phaser.js?d4ef:196794:1)  
> at LoaderPlugin.fileProcessComplete (phaser.js?d4ef:196760:1)  
> at ImageFile.onProcessComplete (phaser.js?d4ef:4961:1)  
> at Image.data.onload (phaser.js?d4ef:19311:1)

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [March 4, 2022, 9:46pm UTC](https://phaser.discourse.group/t/rex-virtual-joystick-cannot-read-properties-of-undefined-reading-get/11348/2 "2022-03-04T21:46:50Z")

</div>

Add

```
console.log(scene, scene.plugins);

```

before that. What are they?

---

<div class="post-metadata">

**Author:** ![stanleyseow](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/stanleyseow/32/1190_2.png) [@stanleyseow](https://phaser.discourse.group/u/stanleyseow)\
**Post date:** [March 5, 2022, 5:14am UTC](https://phaser.discourse.group/t/rex-virtual-joystick-cannot-read-properties-of-undefined-reading-get/11348/3 "2022-03-05T05:14:48Z")

</div>

Updates, I add the following to game config and managed to get the scene and plug-in manager loaded…

```javascript
import VirtualJoystickPlugin from "phaser3-rex-plugins/plugins/virtualjoystick-plugin.js";

plugins: {
        global: [
          {
            key: "rexVirtualJoystick",
            plugin: VirtualJoystickPlugin,
            start: true,
          },
          // ...
        ],
      },

```

and the following changes

```javascript
console.log("scene: ", this.scene);
    console.log("plugins: ", this.scene.scene.plugins);
    var joystick = this.scene.scene.plugins
      .get("rexVirtualJoystick")
      .add(this, {
        x: 100,
        y: 100,
        //radius: 100,
        //base: baseGameObject,
        //thumb: thumbGameObject,
        // dir: '8dir',
        // forceMin: 16,
        // fixed: true,
        // enable: true
      });

```

Console.log …

```javascript
scene: ScenePlugin {scene: world, systems: Systems, settings: {…}, key: 'world', manager: SceneManager, …}

```

```javascript
plugins: PluginManager {_events: Events, _eventsCount: 0, game: Game, plugins: Array(0), scenePlugins: Array(0), …}

```

I m getting this error now …

```javascript
EventEmitterMethods.js?56de:4 Uncaught TypeError: Cannot read properties of undefined (reading 'EventEmitter')
    at VirtualJoyStick.setEventEmitter (EventEmitterMethods.js?56de:4:1)
    at new VirtualJoyStick (VirtualJoyStick.js?b403:15:1)
    at VirtualJoyStickPlugin.add (virtualjoystick-plugin.js?38a6:15:1)
    at world.create (world.js?5e60:87:1)
    at SceneManager.create (phaser.js?d4ef:100338:1)
    at SceneManager.loadComplete (phaser.js?d4ef:100250:1)
    at LoaderPlugin.emit (phaser.js?d4ef:1908:1)
    at LoaderPlugin.loadComplete (phaser.js?d4ef:196794:1)
    at LoaderPlugin.fileProcessComplete (phaser.js?d4ef:196760:1)
    at ImageFile.onProcessComplete (phaser.js?d4ef:4961:1)

```

---

<div class="post-metadata">

**Author:** ![rexrainbow](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/rexrainbow/32/51_2.png) [@rexrainbow](https://phaser.discourse.group/u/rexrainbow)\
**Post date:** [March 5, 2022, 2:20pm UTC](https://phaser.discourse.group/t/rex-virtual-joystick-cannot-read-properties-of-undefined-reading-get/11348/4 "2022-03-05T14:20:27Z")

</div>

The first parameter of `add` method is `scene` instance, according to this line

```javascript
this.scene.scene.plugins.get

```

The `this` variable might not be a `scene` instance.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [March 5, 2022, 3:14pm UTC](https://phaser.discourse.group/t/rex-virtual-joystick-cannot-read-properties-of-undefined-reading-get/11348/5 "2022-03-05T15:14:23Z")

</div>

You should be able to use `this.plugins.get("rexVirtualJoystick")`.

---

<div class="post-metadata">

**Author:** ![stanleyseow](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/stanleyseow/32/1190_2.png) [@stanleyseow](https://phaser.discourse.group/u/stanleyseow)\
**Post date:** [March 11, 2022, 3:09am UTC](https://phaser.discourse.group/t/rex-virtual-joystick-cannot-read-properties-of-undefined-reading-get/11348/6 "2022-03-11T03:09:32Z")

</div>

I think I found out WHY it did not load / work…

One version running OK, Phaser3 was loaded directly from index.html where as the other version (not OK) was launch from Vue.JS mounted() as a div id=“phaser-game”

How do I solve this ?

Any pointers ?

```javascript
<template>
  <div>
    <div id="phaser-game"></div>
  </div>
</template>

 mounted() {
    console.log("startGame mounted", this.gameParams.runOnce);
    window.Phaser = new Game(); 
  },

```

Game Object :

```javascript
export default class Game extends Phaser.Game {
  constructor() {
    const config = {
      type: Phaser.AUTO,
      width: 32 * 35,
      height: 32 * 18,
      physics: {
        default: "arcade",
        arcade: {
          debug: true,
        },
      },
      scale: {
        zoom: 1,
      },
      dom: {
        createContainer: true,
      },
      parent: "phaser-game",
      backgroundColor: "#000000",
      pixelArt: true,
      // Skip loginScene as the Moralis auth is done by Vue side and passed to Phaser
      scene: [
        preload,
        menuScene,
        handleEvents,
        world,
        blockA,
        blockB,
        blockC,
        blockD,
      ],
    };

    super(config);
  }

```

---

<div class="post-metadata">

**Author:** ![stanleyseow](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/stanleyseow/32/1190_2.png) [@stanleyseow](https://phaser.discourse.group/u/stanleyseow)\
**Post date:** [March 14, 2022, 7:47am UTC](https://phaser.discourse.group/t/rex-virtual-joystick-cannot-read-properties-of-undefined-reading-get/11348/7 "2022-03-14T07:47:01Z")

</div>

Fixed here

> [@Rex-plugins: VirtualJoyStick.setEventEmitter Errors](https://phaser.discourse.group/t/rex-plugins-virtualjoystick-seteventemitter-errors/11381):
>
> I hv the following setup , Vue2 loading Phaser3 in a div with phaser3-rex-plugins loading vJoystick I can load vJoystick with Phaser3 standalone but when loaded from Vue, it gives the below errors… vJoystick loaded in world.js Any points on how to resolve this ? Thanks A minimal repo here. phaser is game folder : EventEmitterMethods.js?56de:4 Uncaught TypeError: Cannot read properties of undefined (reading 'EventEmitter') at VirtualJoyStick.setEventEmitter (EventEmitterMethods.js?56de…
