Gamepad not working on WebGL build in browser with new Input System

Hello,

My game works fine using the new Input system on gamepad (wireless xbox controller) and keyboard/mouse for windows builds. This is using input action asset with auto generated c# script.

However, when I create a WEBGL build, only the keyboard/mouse responses work - the gamepad does not.

I have added the option to my game to use the old input manager for the gamepad, and this works fine on WEBGL, suggesting there is no problem with the gamepad through the browser. This is my crude fix for the moment, but it is not great having to combine input systems for different platforms.

Is there a setting or something I am missing that helps enable the WEBGL gamepad use using the new input system?

Any help much appreciated!!
Cheers

Is it safe to assume after a year of waiting that only you and me have this problem on the Unity forum?
Same thing happened to me, but struggling to find someone who has the answer to how to solve it.

Running into this same problem. The keyboard input works fine, but gamepad does not in a WebGL build. There’s nothing out of the ordinary or interesting here, and the fact that the keyboard binds do work for all these same actions, while the gamepad binds do not, makes me think it’s something unique to gamepads and WebGL.


private void Start()
{
    _actionMove = InputSystem.actions.FindAction("Move");
    _actionStick = InputSystem.actions.FindAction("Stick");

    InputSystem.actions.FindAction("SmoothingVelocity").performed += ToggleVelocitySmoothing;
    InputSystem.actions.FindAction("SmoothingTurning").performed += ToggleTurningSmoothing;
    InputSystem.actions.FindAction("InvertPitch").performed += ToggleInvertPitch;
    InputSystem.actions.FindAction("EnableCamMovement").performed += ToggleCamMovement;
    InputSystem.actions.FindAction("SmoothingCamOffset").performed += ToggleCamOffsetSmoothing;
    InputSystem.actions.FindAction("SmoothingCamRotation").performed += ToggleCamRotationSmoothing;
}

private void Update()
{
    var move = _actionMove.ReadValue<Vector2>();
    var stick = _actionStick.ReadValue<Vector2>();
    . . .
}

Based on the fact that this code will crash the WebGL browser, I think something is very wrong with how Gamepads are being read.

Gamepad.current.leftStick.ReadValue();

This has only gotten more confusing because it’s started working again despite me not changing anything. Sometimes it works, sometimes it doesn’t. I can’t find a clear pattern.

After a fresh restart of the computer, it seems guaranteed to not work. Using a PS4 controller with DS4Windows, it seems like if I unplug the controller and then plug it back in, that usually fixes it and I can use it again. In the process of that first unplug though, I get a bunch of WebGL errors thrown, similar to the one above.

Using an Xbox One controller, it seems like it never works? No amount of plugging/unplugging seems to fix the Xbox controller. I wish I had better repro steps.

Is this the issue or maybe similar? I know you say it doesn’t work at all so maybe not…

Same issue in Unity 6.2. Gamepad support would be really cool in my web game, but it just does not work at all. It’s wild how they’re pushing us to use the new Input System when it barely works. The legacy input system (the good one) still has a lot of strange behavior with gamepads. Wired Xbox One controller tested on macOS, built from macOS.

Edit: Small update but no solution. My browser (firefox) does detect the controller, but I have to press the triggers for some reason. I wrote this little debug helper to see what is actually going on:

    public TextMeshProUGUI debug;
    void Update()
    {
        debug.text = "";

        foreach (var d in InputSystem.devices)
        {
            debug.text += $"{d.name}\n";
        }
    }

Keyboard and mouse are detected immediately, as well as a bunch of other random devices I don’t even have are picked up, and once I press the triggers the gamepad pops up as some generic gamepad device, despite appearing through the macOS driver when running this in editor. For some reason, despite clearly being the gamepad (Xbox One, wired), and having gamepad in the name. Unity refuses to believe this is a gamepad. It never appears when using Gamepad.All, the input device never switches even when pressing every button. I’m still trying to see if I can get Unity to detect it as a gamepad, but it’s looking unlikely at the moment. I may have to just cut my losses and scrap the idea.