Controller gamepad not working after reconnection

Hello there,

I am using (and is necessary for my game) a logitech joystick (attack 3 or extreme pro 3) and when it gets disconnected, and want to reconnect it, it doesn't work anymore. and I can't afford to restart the game, the way it is designed.

Does anyone know why, and if so, is there a way to fix it? like if it disconnects and reconnects, it should still work?

Thank you,😛

EDIT: RMMV installed on windows 10, through steam
You should check whether Windows (as i assume you're using it) takes it as a preferred device. Go to Control Panel > Hardware > Devices > Right Click on your controller > Advanced Options. This must be done when your device is connected.
Then choose your gamepad. I don't know if this will fix it since i'm using a PS4 controller and it works after disconnecting and reconnecting (And so do my other 4 generic gamepads).
So, most basic troubleshooting measure - does it work in other games?

That will give a clue as to whether it's an issue in windows, as Erif is referring to, or an issue with your RPG Maker game.

My very first impression is that it shouldn't be anything to do with RPG Maker. MV shouldn't have any way to know - nor should it care - whether your gamepad has been disconnected or not. So long as it's receiving the input from your OS, it should work.

It's also a bit confusing, the way you wrote some of that. Are you saying your gamepad is getting disconnected while playing the game? If so, it's possible that could glitch something...but that's an atypical scenario. Most people are not going to unplug their controllers during play.
So, most basic troubleshooting measure - does it work in other games?

That will give a clue as to whether it's an issue in windows, as Erif is referring to, or an issue with your RPG Maker game.

My very first impression is that it shouldn't be anything to do with RPG Maker. MV shouldn't have any way to know - nor should it care - whether your gamepad has been disconnected or not. So long as it's receiving the input from your OS, it should work.

It's also a bit confusing, the way you wrote some of that. Are you saying your gamepad is getting disconnected while playing the game? If so, it's possible that could glitch something...but that's an atypical scenario. Most people are not going to unplug their controllers during play.
Thank you for your answer. It works in other games, but not RMMV. I know, it is an atypical scenario, but yes it gets disconnected (unintentionally) while playing the game.
This is getting pretty low level into how the engine interacts with input from your operating system.

It's possibly even at the level of how the Chromium browser receives and interacts with input from the operating system, and not have anything to do with code from RPG Maker.

You may just have to wrap some tape around the cord or something so it doesn't pull out when you're in the middle of the game.
If the disconnection is very brief, e.g. "flicker" off/on due to a faulty connection, then you could try to unplug it, wait a second or two, then plug it in again.

MV/MZ simply use the navigator.getGamepads method to re-fetch all connected gamepads every frame before polling them for player inputs, so I imagine this problem will affect other web games. I don't have a gamepad so I can't really test it myself.

Ideas for testing:
  1. Open the dev tools (F8 or F12), type this into the Console tab, and press Enter:

    console.table(navigator.getGamepads ? navigator.getGamepads() : []);
    This should show a list of values, where null represents "no recognised gamepad". You can test before/after disconnect/reconnect to get a feel for whether it's acknowledging the reconnection at the browser level.

  2. Save this as a .js file and importing as a plugin:
    Spoiler: plugin code
    JavaScript:
    /*:
     * @target MV MZ
     * @plugindesc For testing gamepad (dis)connections.
     * @author Caethyril
     * @url https://forums.rpgmakerweb.com/threads/160305/
     * @help Free to use and/or modify for any project, no credit required.
     */
    window.addEventListener("gamepadconnected", function(event) {
      alert("Gamepad " + event.gamepad.index + " connected!");
    });
    window.addEventListener("gamepaddisconnected", function(event) {
      alert("Gamepad " + event.gamepad.index + " disconnected.");
    });
    In theory, it should show a big, obvious message whenever a gamepad connects or disconnects.
I realize this thread is old, ancient even (I was just browsing by tag), so sorry in advance, but if it's unsolved, I can leave a definitive answer for posterity:
EDIT: RMMV installed on windows 10, through steam
This is a specific problem between Steam Input and NWJS/Chromium. Steam Input only reports controllers to NWJS on launch, so any controller connected after launch (even if disconnected and reconnected) will no longer be detected. You can manually disable Steam Input for MV/MZ in the application settings in Steam and this will solve the reconnect issue (on the software side, anyway), though it may cause issues with how NWJS picks up inputs (swapped buttons, non-functional D Pad, etc), depending on the controller. (An old-school flight-sim stick might have mapping issues that were being solved by Steam.)

Original thread: https://forums.rpgmakerweb.com/threads/controller-gamepad-not-working-after-reconnection.160305/