question

DKP avatar image
DKP asked

How to change display name without allowing duplicates,Change display name without allowing duplicates

Hi, I'm trying to write a simple C# script in Unity which allows a user to change their display name but throw up an error if the display name has already been used by someone else. This what I've got so far:

public class StorePlayerName : MonoBehaviour
{
    
    public string _displayName;
    public GameObject _inputField;
    [SerializeField] private TMP_Text _userName;
    
    public void StoreName()
    {
        _displayName = _inputField.GetComponent<TMP_Text>().text;
        _userName.text = _displayName;

        PlayFabClientAPI.UpdateUserTitleDisplayName(new UpdateUserTitleDisplayNameRequest
        {
            DisplayName = _displayName
        }, result =>
        {
        
        }, error =>
        {
            Debug.Log("DISPLAY NAME ALREADY USED");
            Debug.LogError(error.GenerateErrorReport());
        });
        
    }

}

With the above I can change all the user's display names but they can also all be the same name with no issues, which obviously isn't what I want.

Also, 'allow non-unique player display names' is also turned off in my game settings.

Any help greatly appreciated! Cheers

Player Datadata
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

By default, PlayFab won’t allow duplicate DisplayName. Could you please clarify whether you have checked the option “Allow non-unique player display names” before? If so, for clarification, this option cannot be disabled anymore after it was enabled and saved. Specifically, the checkbox of this option will be gray after you checked and saved it, and you cannot uncheck it again. In this case, your title’s players are allowed to use non-unique title display names. You can hover your mouse over the warning sign “(!)” of this option to check the warning information.

If you have never checked the above option, but your players can still update the same title display name. Could you please provide your TitleID the corresponding Players’ PlayFabIds for our reference?

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

DKP avatar image DKP commented ·

Hi Sarah - thank you. I never checked the box, which is why it's so confusing. My title ID is E1F5C, the player name's are Dougal and Dougal. You'll see they both have the same display name. Thanks again

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang DKP commented ·

I searched the "Dougal" in the player query box of your [Game Manager]->[Players] page, only found one player. And after searching the "dougal", it displayed another player.

It means these two players are named "Dougal" and "dougal" separately. And, for clarification, our judgment of the duplicate display names is case-sensitive.

Besides, our Game Manager will display the first letter of the player display name in uppercase, even if it is in lowercase. It is a display design of Game Manager. Please note, the servers and players can get the correct display names using APIs, this design won't affect your actual displayer names.

-1 Like -1 ·
DKP avatar image DKP Sarah Zhang commented ·

Thank you, that totally clears it up! Appreciate it Sarah

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.