Search Unity

Help to understanding how gamepad connections and disconnects works

Discussion in 'New Input System' started by Armetron, Jul 26, 2019.

  1. Armetron


    Oct 7, 2016
    Hello everyone I wanted to ask a few questions that I am hung up on and will hopefully make it easy for anyone searching in the future.

    1) According to the tutorials I've found, once you make an Input system with the Control Scheme, Action Map, and Actions you add the built in Player Input script that will attempt to find an available device that isn't being used by another player input script based on its action map. Is there a way to have a handler assign a specific device to the player inputs manually? If so how?

    2) When the game is running you can see the assigned device in the player input debug window, I have found that if you disconnect the device it will be cleared from the script, however when I reconnect the same device it does not automatically get reassigned to the player input. I have heard mention that the Input System has a way to deal with reconnects but I cant seem to find proper documentation about it. How would I get the device reconnected to the same GameObject or even have a different device of the same type (gamepad) take its spot.

    3) Currently I am working on transferring an old project I made in Gamemaker to Unity, in it I had a character select screen that would detect how many gamepads were connected and would store the selected character and the controllers id number for use in spawning in the next level [0-3] xInput [4-12] dInput. Does the Input system have a way of Identifying or assigning a gamepad with a number?

    Example: (Detects there are 3 xbox controllers and 1 ps4. The xbox are 1, 2, 3 and the ps4 is 4, I unplug xbox 2 and plug in a ps4 gamepad now the new ps4 gamepad is assigned 2.)

    4) And Finally I know that whenever you connect a gamepad unity prompts you that it detected a connection, is there a system event that I can use that fires specifically with gamepads, Kind of like this

    Any help to better understand this new system is greatly appreciated.
  2. N163LPH03N1X


    Jan 10, 2019
    I'm in the same boat, there's no documentation on this because where it's so new. No one knows other than unity. You'd think there was a input reset method. The old Input manager was much easier to use, only problem was disconnecting and reconnecting a controller, which just added an input value. Say if you were player 2 you would be player 3 because of the re detection array. There was no way to reset it.

    I spent most of the time relearning this new input manager and was told that it was able to handle disconnection, now that I have my game finally reworked to the new system. disconnecting removes the paired controller from say Ex: User #0, in the Debug Input window, reconnecting it does not repair this controller. Although if you code say EX: (Gamepad.current.button.wasPressedThisFrame;) the controller that was disconnected still will run this in the code.

    Any events attached to the player input that was using the specific game pad will cease to function until reboot. Unfortunately using that code above occurs for all game pad devices, there is no specific code to to run for one controller. EX: (Gamepad.User #1.button.wasPressedThisFrame;) otherwise I'd chuck away all of the events for one specific button I've had setup in the Input Actions.