Search Unity

  1. 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
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Two Controllers Same UniqeIdentifier (GetHashCode())

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

  1. Birnchen-Studios

    Birnchen-Studios

    Joined:
    Sep 28, 2014
    Posts:
    5
    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):
    1.  
    2.         string[] names = Input.GetJoystickNames();
    3.  
    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.         }
    10.  
    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.

    Greetings
    Pierre
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    4,834
    From the documentation:
    https://msdn.microsoft.com/en-us/library/system.object.gethashcode(v=vs.110).aspx
    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:
    https://docs.unity3d.com/ScriptReference/Input.GetJoystickNames.html
    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

    Birnchen-Studios

    Joined:
    Sep 28, 2014
    Posts:
    5
    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 (http://www.actionxl.com/controllers.html). The First and Only Controller i have seen with this Problems....

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


    Greetings
    Pierre
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    2,719
    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.