Search Unity

Detecting Controllers

Discussion in 'Samsung Smart TV' started by dhivakar, Aug 21, 2014.

  1. dhivakar

    dhivakar

    Joined:
    Jun 21, 2013
    Posts:
    30
    HI,

    I like to know how to check if a particular controller is connected?
    I am currently checking with the

    Input.GetJoystickNames (), it returns with
    Controller (XBOX 360 For Windows) in editor, when i connect the controller to PC and run the game.

    But when i try to do the same in TV, its detecting only the samsungGamePad
    SamsungTV Gamepad

    I am getting the inputs from the controller though, The only problem is detecting is the controller is connected or not.
     
  2. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    271
    Input.GetJoystickNames() currently always returns 1 joystick as SamsungTV Gamepad. In the next version, it will return the actual number of joysticks connected so you can determine if joysticks are connected or not.

    We'll ask Samsung if there is a way of returning the names of the Gamepads, but in the current API I don't think it is possible.
     
  3. dhivakar

    dhivakar

    Joined:
    Jun 21, 2013
    Posts:
    30
    Hi is there any update on this issue ???
     
  4. SimonAlkemade

    SimonAlkemade

    Joined:
    Feb 4, 2009
    Posts:
    432
    I am not familiar with the XBOX 360 controller but I just tested the PS3 controller and that seems to work fine in every way
     
  5. dhivakar

    dhivakar

    Joined:
    Jun 21, 2013
    Posts:
    30
    Hi simon,
    Have you able to check is your PS3 controller is connected or not ?
     
  6. dhivakar

    dhivakar

    Joined:
    Jun 21, 2013
    Posts:
    30
    hi thep3000 can u update the me on this issue ???
     
  7. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    271
    Hi,

    GetJoystickNames works as intended now and returns a list of joystick names from the OS. I don't have an exact date when it will be released, but the next build will contain this fix.
     
  8. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    271
    Hi,

    Here is a build with Input.GetJoystickNames() fixed. Also updated to 4.5.4f1.

    Windows
    Mac
     
    Last edited: Sep 30, 2014
  9. dhivakar

    dhivakar

    Joined:
    Jun 21, 2013
    Posts:
    30
    Hi Thep,

    Thanks for the update. I will check with this version.
     
  10. dhivakar

    dhivakar

    Joined:
    Jun 21, 2013
    Posts:
    30
    Hi in the recent updated unity versions, the connected "Input.GetJoystickNames()" always returning an empty string. Is this intented ?? I have faced this issue in Unity 4.6.4f1 for samsung tv & normal version Unity 4.6.7f1 too.
     
    MWGAECOM likes this.
  11. AlexThibodeau

    AlexThibodeau

    Unity Technologies

    Joined:
    Jul 23, 2013
    Posts:
    309
    I'll add this to the list of things to look into. Thanks for reporting this!
     
  12. AlexThibodeau

    AlexThibodeau

    Unity Technologies

    Joined:
    Jul 23, 2013
    Posts:
    309
    Are you having issues getting the TV to report a connected gamepad? I was able to get this to return a non-string by using touchPadMode = TouchPadMode.Joystick
     
  13. dhivakar

    dhivakar

    Joined:
    Jun 21, 2013
    Posts:
    30
    I am getting all the connected controllers names properly. The problem is i am also getting an extra item in the array with empty string along with all those other connected controllers.
     
  14. robpuk38

    robpuk38

    Joined:
    Nov 25, 2016
    Posts:
    1
    Code (CSharp):
    1. private int Xbox_One_Controller = 0;
    2.      private int PS4_Controller = 0;
    3. void Update()
    4. {
    5. string[] names = Input.GetJoystickNames();
    6.          for (int x = 0; x < names.Length; x++)
    7.          {
    8.              print(names[x].Length);
    9.              if (names[x].Length == 19)
    10.              {
    11.                  print("PS4 CONTROLLER IS CONNECTED");
    12.                  PS4_Controller = 1;
    13.                  Xbox_One_Controller = 0;
    14.              }
    15.              if (names[x].Length == 33)
    16.              {
    17.                  print("XBOX ONE CONTROLLER IS CONNECTED");
    18.                  //set a controller bool to true
    19.                  PS4_Controller = 0;
    20.                  Xbox_One_Controller = 1;
    21.              }
    22.          }
    23. if(Xbox_One_Controller == 1)
    24. {
    25. //do something
    26. }
    27. else if(PS4_Controller == 1)
    28. {
    29. //do something
    30. }
    31. else
    32. {
    33. // there is no controllers
    34. }
    35. }
     
    ConkerJak and ARares like this.
  15. MaxFrax96

    MaxFrax96

    Joined:
    Nov 18, 2012
    Posts:
    11
    Can I assume joystick names won't change in time or changing os/machine setup?