Search Unity

  1. We want you to join us at GDC this year! Take a peek at all of the events we will be hosting during the week of GDC.
    Dismiss Notice
  2. Tell us about your experience here and you’ll get early access to the 2018 Game Studios report + more goodies.
    Dismiss Notice
  3. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  5. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice

Two Controllers Same UniqeIdentifier (GetHashCode())

Discussion in 'Scripting' started by Birnchen-Studios, Sep 13, 2017.

  1. Birnchen-Studios


    Sep 28, 2014
    Hey @ll,

    i have a big Problem and sorry for my bad english^^.
    I am Creating an Sportssimulator and have two Controller (ActionXL).
    I cant change the COntroller, its a must from the Customer....

    So normaly do something like this:
    Code (CSharp):
    2.         string[] names = Input.GetJoystickNames();
    4.         Debug.Log("Connected Joysticks:");
    5.         for (int i = 0; i < names.Length; i++)
    6.         {
    7.             deviceUniqueIdentifier[i] = names[i].GetHashCode();
    8.             Debug.Log("Joystick " + (i + 1) + " = \"" + names[i] + "\" ID: " + deviceUniqueIdentifier[i]);
    9.         }
    So but currently the Problem is, both Controller have the same deviceUniqueIdentifier (
    Code (CSharp):
    1. names[i].GetHashCode()

    Now i am looking for a way to identifie them, while the Controllers are on the backside of a Surfboard and fix in the side. Cant go to the Controller and change the Side, i must do them in the backend of my code and save in the Database (controller one = left or right). The complete Callibration prozess is dependent on this (both side are not exactly same in hight and build).

    Can Anyone help me Please??

    My German is better then my english, if anyone here and can help me in German.

    Thx alot.

  2. lordofduct


    Oct 3, 2011
    From the documentation:
    This can be shown to be quite certain since you're getting a HashCode of a string. Thing is a hashcode is an int, giving 2^32 unique values. Where as a string can have an infinite number of unique values (though technically finite since limited by memory constraints, but still of course is more than 2^32).

    Why not use the index of the joystick as its unique identifier?

    Again from the documentation:
    There can only be 1 joystick in a given slot... so the index of that slot is unique to that joystick.


    Unless you mean that you don't which index a controller is going to end up in, and you need to work out which is which. So say the first time you configure 'left' is in slot 0, but the next time it happens to be in 1, for whatever reason.

    Are the names themselves unique? Check those, instead of calling GetHashCode.
  3. Birnchen-Studios


    Sep 28, 2014
    Hey lordofduct,

    sorry for the late response (and the bad english...).
    The names are equal to...

    The last you say

    is my problem, i dont even know if Joystick 1 is the (Hardware) Joystick one.
    They must be switched in the Backend of the Simulator after installing the Mashine on the Place.

    The other thing is, the Controllers are not even in the same Position for the Motion. That i must calibrate in the Backend and save with the controller in the DB.

    I have tested: HashCode, Typecode, MetadataToken, Names. All are the same on both controller.....
    I Hate this f***** Controller, they are so bad, but the Customer want them.... Its a ActionXL Controller ( The First and Only Controller i have seen with this Problems....

    Yeah and contracts end is on Friday :D i hate this Controller....

  4. guavaman


    Nov 20, 2009
    You can get no information from Unity about a joystick apart from the string returned by Input.GetJoystickNames(). If the string is the same for both joysticks, there's no way you can differentiate the two by type. Your only choice is to have the user press a button on the joystick at some UI prompt to identify which is which.