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

**URL:** <https://forum.playcanvas.com/t/solved-uncaught-typeerror-cannot-read-property-pad-of-undefined/5051>\
**Category:** Suggestions & Feedback\
**Created:** [October 19, 2017, 9:12pm UTC](https://forum.playcanvas.com/t/solved-uncaught-typeerror-cannot-read-property-pad-of-undefined/5051 "2017-10-19T21:12:21Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![matts](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@matts](https://forum.playcanvas.com/u/matts)\
**Post date:** [October 19, 2017, 9:12pm UTC](https://forum.playcanvas.com/t/solved-uncaught-typeerror-cannot-read-property-pad-of-undefined/5051/1 "2017-10-19T21:12:21Z")

</div>

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](http://html5gamepad.com/) to check device and everything _seems_ to o.k

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

Additional:  
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](http://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).

Thanks,  
Matt.

---

<div class="post-metadata">

**Author:** ![vaios](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/vaios/32/4566_2.png) [@vaios](https://forum.playcanvas.com/u/vaios)\
**Post date:** [October 19, 2017, 10:46pm UTC](https://forum.playcanvas.com/t/solved-uncaught-typeerror-cannot-read-property-pad-of-undefined/5051/2 "2017-10-19T22:46:23Z")

</div>

Could you share a link to your project?

---

<div class="post-metadata">

**Author:** ![matts](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@matts](https://forum.playcanvas.com/u/matts)\
**Post date:** [October 20, 2017, 8:51am UTC](https://forum.playcanvas.com/t/solved-uncaught-typeerror-cannot-read-property-pad-of-undefined/5051/3 "2017-10-20T08:51:37Z")

</div>

Sure!

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 ☹

Empty project link: [https://playcanvas.com/editor/scene/560018](https://playcanvas.com/editor/scene/560018)

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

---

<div class="post-metadata">

**Author:** ![dave](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/dave/32/4558_2.png) [@dave](https://forum.playcanvas.com/u/dave)\
**Post date:** [October 20, 2017, 2:07pm UTC](https://forum.playcanvas.com/t/solved-uncaught-typeerror-cannot-read-property-pad-of-undefined/5051/4 "2017-10-20T14:07:42Z")

</div>

[This Pull Request](https://github.com/playcanvas/engine/pull/985) by @OmarShehata was released yesterday. It could be related.

---

<div class="post-metadata">

**Author:** ![OmarShehata](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/omarshehata/32/4761_2.png) [@OmarShehata](https://forum.playcanvas.com/u/OmarShehata)\
**Post date:** [October 21, 2017, 9:35pm UTC](https://forum.playcanvas.com/t/solved-uncaught-typeerror-cannot-read-property-pad-of-undefined/5051/5 "2017-10-21T21:35:05Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![matts](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@matts](https://forum.playcanvas.com/u/matts)\
**Post date:** [October 21, 2017, 10:24pm UTC](https://forum.playcanvas.com/t/solved-uncaught-typeerror-cannot-read-property-pad-of-undefined/5051/6 "2017-10-21T22:24:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![OmarShehata](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/omarshehata/32/4761_2.png) [@OmarShehata](https://forum.playcanvas.com/u/OmarShehata)\
**Post date:** [October 21, 2017, 10:36pm UTC](https://forum.playcanvas.com/t/solved-uncaught-typeerror-cannot-read-property-pad-of-undefined/5051/7 "2017-10-21T22:36:21Z")

</div>

Here should be the fix [https://github.com/playcanvas/engine/pull/1025](https://github.com/playcanvas/engine/pull/1025)

---

<div class="post-metadata">

**Author:** ![will](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/will/32/4560_2.png) [@will](https://forum.playcanvas.com/u/will)\
**Post date:** [October 23, 2017, 11:23pm UTC](https://forum.playcanvas.com/t/solved-uncaught-typeerror-cannot-read-property-pad-of-undefined/5051/8 "2017-10-23T23:23:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![matts](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@matts](https://forum.playcanvas.com/u/matts)\
**Post date:** [October 28, 2017, 4:26pm UTC](https://forum.playcanvas.com/t/solved-uncaught-typeerror-cannot-read-property-pad-of-undefined/5051/9 "2017-10-28T16:26:38Z")

</div>

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](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](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](https://code.playcanvas.com/playcanvas-stable.dbg.js:22863:21))_  
\_ at Func._onUpdate ([https://code.playcanvas.com/playcanvas-stable.dbg.js:22900:14](https://code.playcanvas.com/playcanvas-stable.dbg.js:22900:14))_  
\_ at Func._callComponentMethod ([https://code.playcanvas.com/playcanvas-stable.dbg.js:23129:32](https://code.playcanvas.com/playcanvas-stable.dbg.js:23129:32))_  
\_ at Func._onUpdate ([https://code.playcanvas.com/playcanvas-stable.dbg.js:23139:10](https://code.playcanvas.com/playcanvas-stable.dbg.js:23139:10))_  
\_ at Function.fire ([https://code.playcanvas.com/playcanvas-stable.dbg.js:608:18](https://code.playcanvas.com/playcanvas-stable.dbg.js:608:18))\_  
\_ at Function.update ([https://code.playcanvas.com/playcanvas-stable.dbg.js:20927:23](https://code.playcanvas.com/playcanvas-stable.dbg.js:20927:23))\_  
\_ at Application.update ([https://code.playcanvas.com/playcanvas-stable.dbg.js:20491:24](https://code.playcanvas.com/playcanvas-stable.dbg.js:20491:24))\_  
\_ at Application.tick ([https://code.playcanvas.com/playcanvas-stable.dbg.js:20830:11](https://code.playcanvas.com/playcanvas-stable.dbg.js:20830:11))\_

From this chunk of code in an otherwise empty level:

```javascript
Test.prototype.update = function(dt) {
    var gamepads = new pc.GamePads();
    var pads = gamepads.poll();
    gamepads.update();
    //console.log(pads);
    //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.

Thanks,  
M.

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [October 29, 2017, 10:06am UTC](https://forum.playcanvas.com/t/solved-uncaught-typeerror-cannot-read-property-pad-of-undefined/5051/10 "2017-10-29T10:06:00Z")

</div>

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)](https://forum.playcanvas.com/t/vr-headset-motion-not-working-when-forked-lab/5106/7?u=yaustar)

---

<div class="post-metadata">

**Author:** ![matts](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@matts](https://forum.playcanvas.com/u/matts)\
**Post date:** [November 1, 2017, 9:21pm UTC](https://forum.playcanvas.com/t/solved-uncaught-typeerror-cannot-read-property-pad-of-undefined/5051/11 "2017-11-01T21:21:13Z")

</div>

Seems the fix has gone in, thanks guys!

m.
