question

creativeaidev avatar image
creativeaidev asked

DisplayName is returning null

I'm trying to log the user in and get the username.

When I try to get username on LoginSuccess() via "InfoResultPayload.PlayerProfile.DisplayName" it's returning null. Here's are the login functions:

public void LoginClick()
    {
        var login = new LoginWithPlayFabRequest { Username = Username.text, Password = Password.text,
        InfoRequestParameters = new GetPlayerCombinedInfoRequestParams { GetPlayerProfile = true }
        };
        PlayFabClientAPI.LoginWithPlayFab(login, OnLoginSuccess, OnLoginFailure);
    }


    private void OnLoginSuccess(LoginResult result)
    {
        //ErrorMessage.text = "";
        //SceneManager.LoadScene(SceneName); // Load Main Scene
        Debug.Log(Username);
        string name = null;
        if(result.InfoResultPayload.PlayerProfile != null)
        {
            name = result.InfoResultPayload.PlayerProfile.DisplayName;
            ErrorMessage.text = name;
            Debug.Log(name);
        }
        
    }

And this is how I registered the user -

 public void RegisterClick()
    {
        var register = new RegisterPlayFabUserRequest { Username = Username.text, Email = Email.text, Password = Password.text };
        PlayFabClientAPI.RegisterPlayFabUser(register, OnRegisterSuccess, OnRegisterFailure);
    }


    private void OnRegisterSuccess(RegisterPlayFabUserResult result)
    {
        ErrorMessage.text = "";
        SceneManager.LoadScene(SceneName); // Load Main Scene


    }

Why am I getting "null" when logging in and how can I get the username of the user?

Player Data
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

·
Gosen Gao avatar image
Gosen Gao answered

The Display Name is not the Username, it should be

result.InfoResultPayload.AccountInfo.Username

Refer to LoginWithPlayFab--UserAccountInfo.

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.