Issue with player names on leaderboards

Hi there,

I have encountered an issue in my game with player names in the Leaderboards api.

My game runs on the Oculus/Meta Quest platform. When we sign users into the unity authentication back end, we update their player name with the following code:

string cachedUnityPlayerName = AuthenticationService.Instance.PlayerName;
string unityPlayerNameBase = string.IsNullOrEmpty(cachedUnityPlayerName) ? "" : cachedUnityPlayerName.Split('#')[0];
if (string.IsNullOrEmpty(cachedUnityPlayerName) || !unityPlayerNameBase.Contains(oculusPlayerName))
{
    Debug.Log($"[Authentication] Oculus player: {oculusPlayerName} updating player name");
    if (oculusPlayerName.Any(char.IsWhiteSpace))
    {
        oculusPlayerName = oculusPlayerName.Replace(' ', '_');
        Debug.Log($"[Authentication] Oculus player has whitespaces in their name, replace with underscores. Oculus player name for authentication is now: {oculusPlayerName}");
    }
    await AuthenticationService.Instance.UpdatePlayerNameAsync(oculusPlayerName);
}

After this code runs, we also upload the player name to cloud save as a publically accessible variable, because the Authentication player name is not directly accessible (can’t figure out why this is not a feature):

var data = new Dictionary<string, object> { { "playerName", oculusPlayerName} };
await CloudSaveService.Instance.Data.Player.SaveAsync(data, new SaveOptions(new PublicWriteAccessClassOptions()));

Some of our users have reported that their names are being displayed incorrectly in the leaderboard. Here is an example: In the attached screenshot, the player in first place has what appears to be a randomly generated username “SarcasticOrganizedLynx”. I have double checked in the Unity cloud dasboard, and the correct name is being uploaded to cloud save, but clearly not to the Authentication Service.

Can anyone explain why there is a mismatch?

1 Like

I know this thread is old, but it can help others:

This random name is created when you call:

  • AuthenticationService.Instance.GetPlayerNameAsync()

if you do not want the name to get auto-generated, you have to pass false:

  • AuthenticationService.Instance.GetPlayerNameAsync(autoGenerate: false)