Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Can I remove the numbers at the end of a player name?

Discussion in 'Leaderboards' started by Airtap, Aug 30, 2023.

  1. Airtap

    Airtap

    Joined:
    May 16, 2023
    Posts:
    5
    Hey everyone this is my first thread here and i'm a beginner so apologies if I don't make sense somewhere in this thread!

    I've been trying to implement the leaderboard in my first game for the past week and I found out today that upon submitting/posting a score entry to the leaderboard, you can allow the player to set their own player name when submitting a score, an example would be something like this:
    [SerializeField]
    private TMPro.TMP_InputField nameInput;

    public async void PostScore(ScoreType type, float score)
    {
    if (score <= 0) return;
    try
    {
    await LeaderboardsService.Instance.AddPlayerScoreAsync(type.ToString(), score);
    await AuthenticationService.Instance.UpdatePlayerNameAsync(nameInput.text);

    Debug.Log($"Score Posted To Leaderboard - {type}. Score: {score}");

    }
    catch (System.Exception e)
    {
    Debug.LogException(e);
    await Task.Delay(2500);
    PostScore(type, score);
    }
    }

    But when I fetch the leaderboard entries on my leaderboard, whatever I put in the inputfield, for example "TestPlayer", it shows TestPlayer#4382. I'm just wondering if it's possible to remove the digits at the end?
     
  2. EmilF_Unity

    EmilF_Unity

    Unity Technologies

    Joined:
    Jun 10, 2022
    Posts:
    16
    Hi Airtap,

    Welcome to the forum and congrats on making your first game!

    Regarding the player name, the hash and numbers are an integral part of the player management solution and cannot be removed from the service responses (see these docs for more details on player names). However, because the pattern is predictable you can always remove them from the string wherever you need to display the name.
     
  3. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    384
    I remove the last digits this way:

    Code (CSharp):
    1. string playerName = await AuthenticationService.Instance.GetPlayerNameAsync();
    2.  
    3. playerName = string.Join("", playerName.SkipLast(5));
     
  4. restush96

    restush96

    Joined:
    May 28, 2019
    Posts:
    129
    No need to remove because there must be a duplicate name then the hash could help player to distinguish their real account.

    Like would be pain to distinguish these leaderboard.
    1. Carrot
    2. Carrot
    3. ... etc