question

manolhsplaths46 avatar image
manolhsplaths46 asked

How to check if display name exists?

Using unity ,

So how can i check if display name exists?

What i am looking for is the first time the user signs enter his displayname but the next time the user tries to log in i want to say


Hey

if(Displayname == exists ){

then go to next page

}else{

let's add your DisplayName

}

my code so far:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;
using UnityEngine.UI;
using System;

public class PlayFabAccount : MonoBehaviour {

    public InputField inputPlayerName;
    public GameObject accountPanel;

    public void UpdatePlayerName()
    {
        // Hole Text aus dem InputFeld
        string text = inputPlayerName.text;

        // Wenn das Textfeld nicht leer ist, dann Spielernamen aktualisieren
        if (text != null)
        {
            // Request erstellen
            var request = new UpdateUserTitleDisplayNameRequest();
            request.DisplayName = text.ToString();
            // API Anfrage
            PlayFabClientAPI.UpdateUserTitleDisplayName(request, OnPlayerNameResult, OnPlayFabError);

        }
    }

    public void ChangePanel()
    {
        if (accountPanel.activeSelf)
        {
            accountPanel.SetActive(false);
        }
        else
        {
            accountPanel.SetActive(true);

        }

    }


    private void OnPlayFabError(PlayFabError obj)
    {
        print("Error: " + obj.Error);
    }

    private void OnPlayerNameResult(UpdateUserTitleDisplayNameResult obj)
    {
        print("Spielername wurde aktualsiert: " + obj.DisplayName);
    }
}
unity3d
10 |1200

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

JayZuo avatar image
JayZuo answered

Once the user has logged in, you can use GetPlayerProfile to retrieve the DisplayName. And if it's null or empty, then the display name is not set, you will need to update player name. For example:

PlayFabClientAPI.GetPlayerProfile(new GetPlayerProfileRequest { ProfileConstraints = new PlayerProfileViewConstraints { ShowDisplayName = true } },
    result =>
    {
        if (string.IsNullOrEmpty(result.PlayerProfile.DisplayName))
        {
            UpdatePlayerName();
        }
        else
        {
            //go to next page
        }
    },
    error => { Debug.LogError(error.GenerateErrorReport()); });
1 comment
10 |1200

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

manolhsplaths46 avatar image manolhsplaths46 commented ·

i fixed in a different way i made it so that when someone register he had to register the username as well.

0 Likes 0 ·
Nisan Bahar avatar image
Nisan Bahar answered

@manolhsplaths46 This still may not solve your issue since the user can just close the application before submitting the username, and then opening it again, leading the username to be null.

10 |1200

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

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.