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. Dismiss Notice

Question How to make a "specific" unpaired Device list?

Discussion in 'Input System' started by Pandarne, Apr 9, 2021.

  1. Pandarne

    Pandarne

    Joined:
    Sep 13, 2014
    Posts:
    4
    Hejhej, I've been staring at the documentation for 3 days now and I'm getting where i want to be.
    But I wasnt able to find anything regarding this:
    There is the function GetUnpairedInputDevices which reads out a list. But I need this list with only the XInputcontroller or gamepads for now. So that i can do something like:
    var allUnpairedDevices = InputUser.GetUnpairedInputDevices();
    gamepad = allUnpairedDevices[0]
    I know this is not the best code and it would be much cleaner to ask for an input of the user and assign that input to a gamepad, but I'm not not able to do that either.
    Thank you out there for making this Inputcontroller :)
     
    Last edited: Apr 10, 2021
  2. Pandarne

    Pandarne

    Joined:
    Sep 13, 2014
    Posts:
    4
    if there is any information i can give you to make my problem more clear, I'll post them right away :)
     
  3. Holonet

    Holonet

    Joined:
    Aug 14, 2017
    Posts:
    84
    This should work:

    Code (CSharp):
    1. var allUnpairedDevices = InputUser.GetUnpairedInputDevices();
    2.  
    3. foreach (var dev in allUnpairedDevices)
    4. {
    5.      if (dev.device.ToString().Contains("XInput"))
    6.      {
    7.           Debug.Log(dev.displayName);
    8.           Debug.Log("Unconnected XInput controller, oh yeah.");
    9.      }
    10. }
    In the loop, you can just add them to your own list or do what you like w/ it :)
     
  4. Pandarne

    Pandarne

    Joined:
    Sep 13, 2014
    Posts:
    4
    Thanks so much! This is so simple.. I guess i just needed some input from outside on this topic. This helps so much! :)