Search Unity

Is SystemInfo.deviceUniqueIdentifier really unique per device?

Discussion in 'Editor & General Support' started by breban1, May 21, 2019.

  1. breban1

    breban1

    Joined:
    Jun 7, 2016
    Posts:
    194
    I'm considering using SystemInfo.deviceUniqueIdentifier in Unity 2017 LTS to uniquely identify players. I plan on saving it to a server database (hashed/encrypted/etc.). Is it safe to use it so I don't have collisions with IDs between players? I would like to use it for Android AND iOS. I'm finding all kinds of answers to this with searches on the internet, but from the most recent Unity docs it seems completely safe (I'm fine with the pre-iOS7 device caveat). Hoping a Unity person can reply so I know for sure.

    According to the Unity docs:

    iOS: on pre-iOS7 devices it will return hash of MAC address. On iOS7 devices it will be UIDevice identifierForVendor or, if that fails for any reason, advertisingIdentifier.

    Android: SystemInfo.deviceUniqueIdentifier always returns the md5 of ANDROID_ID. (See https://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID).

    So is it actually unique for every device?
     
  2. breban1

    breban1

    Joined:
    Jun 7, 2016
    Posts:
    194
    After doing a bunch of uninstalls/reinstalls of my app, it looks like the deviceUniqueIdentifier can in fact change on iOS between installs. I haven't seen it change on Android yet.

    From https://docs.unity3d.com/ScriptReference/SystemInfo-deviceUniqueIdentifier.html
    A unique device identifier. It is guaranteed to be unique for every device (Read Only).

    So can the SystemInfo.deviceUniqueIdentifier have collisions between devices? I'm assuming so, but it sure would be nice to know for sure by someone from Unity. Thanks!
     
    antikytera likes this.
  3. tsibiski

    tsibiski

    Joined:
    Jul 11, 2016
    Posts:
    599
    Are you suuuuuuure you want to use that? That triggers some nasty looking, not so friendly permission demands client side. At least on Android, you will be prompted to allow the app to manage your phone and make phone calls, which can turn people off. Unless that has changed with Android 9. I think you get something similar on iOS.

    And the purpose of that unique identifier is to be, indeed, unique. There will never be another device with that ID. At least, of the same type of device (iOS vs Android, and they are pretty different anyway, so you won't have matches between iOS and Android). And a device's ID should never change, ever. If it is changing between checks, something weird is happening.

    If you install Xcode command line, run "instruments -s devices", and for android, get the dev tools and adb and run "adb devices". Those will display the UDID's of any connected devices. These will never change. If it doesn't match what you get from SystemInfo.uniqueDeviceIdentifier, then there is something wrong.
     
  4. breban1

    breban1

    Joined:
    Jun 7, 2016
    Posts:
    194
    Thanks for the response @tsibiski

    It looks like iOS doesn't give a way to retrieve the UDID anymore as it is a security concern. I am going to try another way of uniquely identifying players, although it won't be "permanent".
     
  5. tsibiski

    tsibiski

    Joined:
    Jul 11, 2016
    Posts:
    599
    One possibility would be to save a System.Guid.NewGuid() into the game files on the device. If it already exists, then you use that when communicating with the server. And as long as that user does not uninstall and reinstall, then you will have a fairly unique identifier. Not perfect, but it would give you a way to make a user + user-device separate from one another, in addition to accounts (or in lieu of accounts).