I get getGamepad warnings but I'm not using gamepads at all

I started getting getGamepad warnings in HTTP context.

But my real problem is that I don’t use and I don’t want to use gamepads at all :thinking:

How to fully disable gamepads? Is there any option to pass to Scene constructor? (I don’t see any related to input device)

Source code from webDeviceInputSystem: Babylon.js/webDeviceInputSystem.ts at 9d3d72ab1e5b09ab394f4d8c23371f18d7f052f9 · BabylonJS/Babylon.js · GitHub

 * Checks for existing connections to devices and register them, if necessary
 * Currently handles gamepads and mouse
private _checkForConnectedDevices(): void {
    if (navigator.getGamepads) {
        const gamepads = navigator.getGamepads();

        for (const gamepad of gamepads) {
            if (gamepad) {

    // If the device in use has mouse capabilities, pre-register mouse
    if (typeof matchMedia === "function" && matchMedia("(pointer:fine)").matches) {
        // This will provide a dummy value for the cursor position and is expected to be overridden when the first mouse event happens.
        // There isn't any good way to get the current position outside of a pointer event so that's why this was done.
        this._addPointerDevice(DeviceType.Mouse, 0, 0, 0);

The best would be to totally remove gamepads support from source code via Webpack tree shaking.

How to achieve that?

Related to:

cc @PolygonalSun

1 Like

The reason this error is coming is because of the getGamepads() call which we use to see if there are any gamepad available. As far as settings to pass, there aren’t any built-in ways to disable the initial getGamepads() call. I could see a check for isSecureContext being added to try and skip the call. I’ll get it added when I can.

Note sure this is a good idea.
I think we better avoid “magic” behaviour depending on browser context (and maybe some people uses gamepad and test it on local dev server with no secure context and don’t mind about the warning).

It’s way better to add an explicit scene option that disables the gamepad feature.

The best would be to have a gamepad option that is an instance of a class (dependency injection) so that having NO gamepad support will don’t have the code at all. But I think that’s maybe too much and a simple gamepad option boolean will do the job.

Perhaps you’re right. I know that localhost is technically considered a secure context but for anyone testing via a local network (192.168.#.#), it would break them.

As far as adding a boolean to the scene to disable support, all input is handled at the engine level so if we were to disable it for one scene, we’d have to disable it for all scenes or the warning would still occur (in cases of multiple scenes being active, at least theoretically). I could see an option to explicitly omit certain inputs at the Engine level but I’d have to think about how it should be done as there are future plans to make the whole input system modular/extensible