[SOLVED] Uncaught TypeError: Cannot read property 'pad' of undefined

Hi all,

Last night all was fine, came back to continue working on my project tonight and suddenly PlayCanvas is throwing these errors with USB game device attached:

caught TypeError: Cannot read property ‘pad’ of undefined
at GamePads.update (playcanvas-stable.dbg.js:18314)
at Application.update (playcanvas-stable.dbg.js:20503)
at playcanvas-stable.dbg.js:20829

100% repro on a brand new empty project
Tested in Chrome and Edge
Error triggered when input is detected from game device
Tested on two PCs with same result
Errors with either or both of the following USB game devices attached: MS 360 gamepad, Fanatec Clubsport peddles.
Have loaded up html5gamepad.com to check device and everything seems to o.k

I’m at a real loss here, any help appreciated!

Unplugged all USB game devices so I could carry on working on other functionality and the same error was still being thrown on launch. html5gamepad.com and Windows USB devices were all showing nothing connected. Had to restart browser and this seemed to stop error (with no gamepad connected, reconnecting generates error again).


Could you share a link to your project?


So, I’ve just got into work (different PC, gamepad), launched the empty project in a new browser window (link below) and immediately hitting the same error as soon as I nudge one of the controller sticks. I don’t get it, it’s a brand new empty project with no code :frowning:

Empty project link: https://playcanvas.com/editor/scene/560018

Project where I first hit the issue: https://playcanvas.com/editor/scene/555463

This Pull Request by @OmarShehata was released yesterday. It could be related.

1 Like

@dave is right - looks like it’s my fault. I’m sorry this is stifling your work @matts.

I do know what the problem is (it seems a last minute change caused the gamepad update method to essentially stop working). I’ll make a pull request to fix it shortly. Although when it gets released will depend on the PlayCanvas team.

Hey no problem, looking into other areas at the moment and running around using the keyboard :smiley:

Here should be the fix https://github.com/playcanvas/engine/pull/1025

Hey @matts, @OmarShehata’s fix is now deployed to production. Can you verify that all is now well? Thanks! :smiley:

1 Like

Hi there, apologies for not getting back sooner it’s been a busy week.

I’m not certain that things are working entirely as they should, or at least something about how gamepad data is returned has changed. I’m now getting this error:

[playcanvas-stable.dbg.js:18368]: Cannot read property ‘0’ of undefined

TypeError: Cannot read property ‘0’ of undefined
_ at GamePads.getAxis (https://code.playcanvas.com/playcanvas-stable.dbg.js:18368:45)_
_ at script.Test.update (https://launch.playcanvas.com/api/assets/files/test.js?id=9650542:15:33)_
_ at Func.scriptMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:22863:21)
_ at Func.onUpdate (https://code.playcanvas.com/playcanvas-stable.dbg.js:22900:14)
_ at Func.callComponentMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:23129:32)
_ at Func.onUpdate (https://code.playcanvas.com/playcanvas-stable.dbg.js:23139:10)
_ at Function.fire (https://code.playcanvas.com/playcanvas-stable.dbg.js:608:18)_
_ at Function.update (https://code.playcanvas.com/playcanvas-stable.dbg.js:20927:23)_
_ at Application.update (https://code.playcanvas.com/playcanvas-stable.dbg.js:20491:24)_
_ at Application.tick (https://code.playcanvas.com/playcanvas-stable.dbg.js:20830:11)_

From this chunk of code in an otherwise empty level:

Test.prototype.update = function(dt) {
    var gamepads = new pc.GamePads();
    var pads = gamepads.poll();
    //console.log(gamepads.getAxis(pc.PAD_1, pc.PAD_L_STICK_X));
    lvec = new pc.Vec2(gamepads.getAxis(pc.PAD_1, pc.PAD_L_STICK_X), gamepads.getAxis(pc.PAD_1, pc.PAD_L_STICK_Y));
    console.log(lvec.x + '        ' + lvec.y);

I believe the gamepad index is correct; it’s the only device plugged in and using an index that I know to be incorrect doesn’t generate an error.


I believe a fix is in the works.

In the meantime, Dave has given a solution to revert to the old behaviour here VR headset motion not working when forked (LAB)

Seems the fix has gone in, thanks guys!


1 Like