Search Unity

Question How to get the Unity ID from within the game

Discussion in 'Authentication' started by 8bitgoose, Oct 14, 2022.

  1. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    I would like to get the unique GUID from inside my game when entered into the console. This is to update a player's data if something goes wrong.

    Is there a function call to get this ID? I know it is in player prefs but the key is the Unity ID and this may get messy.

    Thanks!
     
  2. RandolfKlemola

    RandolfKlemola

    Unity Technologies

    Joined:
    May 1, 2020
    Posts:
    130
    Hey there 8bitgoose,

    Thanks for reaching out! Could you clarify which ID you're specifically trying to retrieve? The player? The game? something else? Thanks!
     
  3. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    Hi @RandolfKlemola

    I am looking for the Player ID, same one that you see when pulling up Player Management. I just want a simple call to ask from CloudSave or Authentication to get the long API key.

    I want it so a player can bring up the console and ask for their own ID and have it spit back.

    Thanks!
     
  4. RandolfKlemola

    RandolfKlemola

    Unity Technologies

    Joined:
    May 1, 2020
    Posts:
    130
    Ah okay, thank you for the clarification! The sample code for the Unity Authentication service contains a snippet that is meant to display a player's PlayerID in the Unity Editor console:

    Code (CSharp):
    1.  Debug.Log($"PlayerID: {AuthenticationService.Instance.PlayerId}");
    So the line snippet [AuthenticationService.Instance.PlayerId] will pull up a player's PlayerID.

    I believe using this, you'll be able to write it into your game so a player can choose to have it displayed if they'd like!

    Best,
    Randy
     
  5. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    Thanks @RandolfKlemola, I don't know how I missed that. I feel like an idiot now!
     
  6. RandolfKlemola

    RandolfKlemola

    Unity Technologies

    Joined:
    May 1, 2020
    Posts:
    130
    Hey, no need for feeling like that! It happens to all of us. I'm happy it's all sorted!
     
  7. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    Figured it out, works like a charm.