Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Bug New Input System fails to recognize gamepad if it wasn't on before application start

Discussion in 'Input System' started by Lork, Oct 12, 2022.

  1. Lork

    Lork

    Joined:
    Jul 12, 2013
    Posts:
    79
    The new Input system will only accept gamepad input if the gamepad in question was already turned on / plugged in before the game started. Once this condition has been met you can turn the pad off and on and it'll continue to work just fine, but if it wasn't on in the first place, it'll never work.

    This is a pretty serious regression from the old input system, so I'd like to know if anybody has a workaround.
     
  2. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    303
    Please report the bug.
     
  3. Lork

    Lork

    Joined:
    Jul 12, 2013
    Posts:
    79
    I figured out a workaround. The problem is that when you turn on a gamepad (or perhaps any device) after the game has started, it doesn't pair it with an InputUser. You need to manually pair it with something like this.
    Code (CSharp):
    1. InputSystem.onDeviceChange += (device, change) =>
    2. {
    3.    if(change == InputDeviceChange.Added)
    4.       InputUser.PerformPairingWithDevice(device, PInput.user, InputUserPairingOptions.ForceNoPlatformUserAccountSelection);
    5. };
    6.  
    I haven't reported it as a bug yet because I thought it might have been intentional behavior, to do with supporting local multiplayer (but then why automatically pair it with the default user if it was on to start?).

    Then again, even if it was intentional, it's ill conceived and not covered by the documentation, so I suppose I should.

    Edit: I found the event for when a gamepad is connected.
     
    Last edited: Oct 14, 2022