question

tranthony77 avatar image
tranthony77 asked

Issue with result.InfoResultPayload always resulting null,Problem with result.InfoResultPayload

I am running into an issue where result.InfoResultPayload is always null. For my game, I am trying to display the 'Display Name' instead of the PlayFab ID in my leaderboard. I made sure to put the correct InfoRequestParameters variables in my Login() function and also checked the settings in m dashboard with Display Name checked in my client profile options tab. Here is my Playfab manager script:

" using System.Collections; using System.Collections.Generic; using UnityEngine; using PlayFab; using PlayFab.ClientModels; using UnityEngine.UI; using JetBrains.Annotations; using TMPro; using Photon.Pun.Demo.PunBasics;

public class PlayfabManager : MonoBehaviour { [Header("Windows")] public GameObject nameWindow; public GameObject leaderboardWindow; public InputField nameInput;

 [Header("Leaderboard")]
 public GameObject rowPrefab;
 public Transform rowsParent;

 [Header("UI")]
 public TMP_Text messageText;

 public InputField emailInput;
 public InputField passwordInput;

 public void RegisterButton() {
     if (passwordInput.text.Length < 6) {
         messageText.text = "PASSWORD TOO SHORT!";
         return;
     }
     var request = new RegisterPlayFabUserRequest {
         Email = emailInput.text,
         Password = passwordInput.text,
         RequireBothUsernameAndEmail = false
     };
     PlayFabClientAPI.RegisterPlayFabUser(request, OnRegisterSuccess, OnError);
 }

 void OnRegisterSuccess(RegisterPlayFabUserResult result) {
     messageText.text = "REGISTERED AND LOGGED IN!";
 }

 public void LoginButton() {
     var request = new LoginWithEmailAddressRequest {
         Email = emailInput.text,
         Password = passwordInput.text
     };
     PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnError);
 }

 public void ResetPasswordButton() {
     var request = new SendAccountRecoveryEmailRequest {
         Email = emailInput.text,
         TitleId = "3C3FD"
     };
     PlayFabClientAPI.SendAccountRecoveryEmail(request, OnPasswordReset, OnError);
 }

 void OnPasswordReset(SendAccountRecoveryEmailResult result) {
     messageText.text = "PASSWORD RECOVERY SENT!";
 }

 // Start is called before the first frame update
 void Start()
 {

 }

 // Update is called once per frame
 void Login()
 {
     var request = new LoginWithCustomIDRequest {
         CustomId = SystemInfo.deviceUniqueIdentifier,
         CreateAccount = true,
         InfoRequestParameters = new GetPlayerCombinedInfoRequestParams {
             GetPlayerProfile = true,
             GetUserAccountInfo = true,
             GetTitleData = true,
             ProfileConstraints = new PlayerProfileViewConstraints {
                 ShowDisplayName = true,
             },
         },
     };
     Debug.Log("Sending login request with custom ID: " + request.CustomId);
     PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnError);
 }

 void OnLoginSuccess(LoginResult result) {
     Debug.Log("OnLoginSuccess called");

     if (messageText == null) {
         Debug.LogError("messageText is null");
         return; // Early exit if messageText is null to prevent further issues
     }

     messageText.text = "LOGGED IN!";
     Debug.Log("Successful login/account create!");

     if (result == null) {
         Debug.LogError("Login result is null");
         return; // Check if the result is null
     }

     if (result.InfoResultPayload == null) {
         Debug.LogError("InfoResultPayload is null");
         return; // Check if InfoResultPayload is null
     }

     if (result.InfoResultPayload.PlayerProfile == null) {
         Debug.LogError("PlayerProfile is null");
         return; // Check if PlayerProfile is null
     }

     string name = result.InfoResultPayload.PlayerProfile.DisplayName;
     if (name == null) {
         Debug.LogError("DisplayName is null");
         nameWindow.SetActive(true);
     } else {
         leaderboardWindow.SetActive(true);
     }
 }

 public void SubmitNameButton() {
     var request = new UpdateUserTitleDisplayNameRequest {
         DisplayName = nameInput.text,
     };
     PlayFabClientAPI.UpdateUserTitleDisplayName(request, OnDisplayNameUpdate, OnError);
 }

 void OnDisplayNameUpdate(UpdateUserTitleDisplayNameResult result) {
     Debug.Log("UPDATED USERNAME!");
     leaderboardWindow.SetActive(true);
 }

 void OnError(PlayFabError error) {
     Debug.LogError("An error occurred: " + error.GenerateErrorReport());
     if (messageText != null) {
         messageText.text = error.ErrorMessage;
     }
 }

 public void SendLeaderboard(int score) {
     var request = new UpdatePlayerStatisticsRequest {
         Statistics = new List<StatisticUpdate> {
             new StatisticUpdate {
                 StatisticName = "Score Leaderboard",
                 Value = score
             }
         }
     };
     PlayFabClientAPI.UpdatePlayerStatistics(request, OnLeaderboardUpdate, OnError);
 }

 void OnLeaderboardUpdate(UpdatePlayerStatisticsResult result) {
     Debug.Log("Successful leaderboard sent");
 }

 public void GetLeaderboard() {
     var request = new GetLeaderboardRequest {
         StatisticName = "Score Leaderboard",
         StartPosition = 0,
         MaxResultsCount = 10
     };
     PlayFabClientAPI.GetLeaderboard(request, OnLeaderboardGet, OnError);
 }

 void OnLeaderboardGet(GetLeaderboardResult result) {

     foreach (Transform item in rowsParent) {
         Destroy(item.gameObject);
     }

     foreach (var item in result.Leaderboard) {
         GameObject newGo = Instantiate(rowPrefab, rowsParent);
         TMP_Text[] texts = newGo.GetComponentsInChildren<TMP_Text>();
         Debug.Log("Number of TMP_Text components: " + texts.Length);
         texts[0].text = (item.Position + 1).ToString();
         texts[1].text = item.DisplayName;
         texts[2].text = item.StatValue.ToString();

         Debug.Log(item.Position + " " + item.PlayFabId + " " + item.StatValue);
     }
 }

}

The main issue is in my "result.InfoResultPayload.PlayerProfile" which is always null. An explanation on how to fix this would be greatly appreciated. ,I am running into an issue where result.InfoResultPayload is always null. For my game, I am trying to display the 'Display Name' instead of the PlayFab ID. I made sure to put the correct InfoRequestParameters variables in my Login() function. Here is my Playfab manager script: " using System.Collections; using System.Collections.Generic; using UnityEngine; using PlayFab; using PlayFab.ClientModels; using UnityEngine.UI; using JetBrains.Annotations; using TMPro; using Photon.Pun.Demo.PunBasics;

public class PlayfabManager : MonoBehaviour { [Header("Windows")] public GameObject nameWindow; public GameObject leaderboardWindow; public InputField nameInput;

 [Header("Leaderboard")]
 public GameObject rowPrefab;
 public Transform rowsParent;

 [Header("UI")]
 public TMP_Text messageText;

 public InputField emailInput;
 public InputField passwordInput;

 public void RegisterButton() {
     if (passwordInput.text.Length < 6) {
         messageText.text = "PASSWORD TOO SHORT!";
         return;
     }
     var request = new RegisterPlayFabUserRequest {
         Email = emailInput.text,
         Password = passwordInput.text,
         RequireBothUsernameAndEmail = false
     };
     PlayFabClientAPI.RegisterPlayFabUser(request, OnRegisterSuccess, OnError);
 }

 void OnRegisterSuccess(RegisterPlayFabUserResult result) {
     messageText.text = "REGISTERED AND LOGGED IN!";
 }

 public void LoginButton() {
     var request = new LoginWithEmailAddressRequest {
         Email = emailInput.text,
         Password = passwordInput.text
     };
     PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnError);
 }

 public void ResetPasswordButton() {
     var request = new SendAccountRecoveryEmailRequest {
         Email = emailInput.text,
         TitleId = "3C3FD"
     };
     PlayFabClientAPI.SendAccountRecoveryEmail(request, OnPasswordReset, OnError);
 }

 void OnPasswordReset(SendAccountRecoveryEmailResult result) {
     messageText.text = "PASSWORD RECOVERY SENT!";
 }

 // Start is called before the first frame update
 void Start()
 {

 }

 // Update is called once per frame
 void Login()
 {
     var request = new LoginWithCustomIDRequest {
         CustomId = SystemInfo.deviceUniqueIdentifier,
         CreateAccount = true,
         InfoRequestParameters = new GetPlayerCombinedInfoRequestParams {
             GetPlayerProfile = true,
             GetUserAccountInfo = true,
             GetTitleData = true,
             ProfileConstraints = new PlayerProfileViewConstraints {
                 ShowDisplayName = true,
             },
         },
     };
     Debug.Log("Sending login request with custom ID: " + request.CustomId);
     PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnError);
 }

 void OnLoginSuccess(LoginResult result) {
     Debug.Log("OnLoginSuccess called");

     if (messageText == null) {
         Debug.LogError("messageText is null");
         return; // Early exit if messageText is null to prevent further issues
     }

     messageText.text = "LOGGED IN!";
     Debug.Log("Successful login/account create!");

     if (result == null) {
         Debug.LogError("Login result is null");
         return; // Check if the result is null
     }

     if (result.InfoResultPayload == null) {
         Debug.LogError("InfoResultPayload is null");
         return; // Check if InfoResultPayload is null
     }

     if (result.InfoResultPayload.PlayerProfile == null) {
         Debug.LogError("PlayerProfile is null");
         return; // Check if PlayerProfile is null
     }

     string name = result.InfoResultPayload.PlayerProfile.DisplayName;
     if (name == null) {
         Debug.LogError("DisplayName is null");
         nameWindow.SetActive(true);
     } else {
         leaderboardWindow.SetActive(true);
     }
 }

 public void SubmitNameButton() {
     var request = new UpdateUserTitleDisplayNameRequest {
         DisplayName = nameInput.text,
     };
     PlayFabClientAPI.UpdateUserTitleDisplayName(request, OnDisplayNameUpdate, OnError);
 }

 void OnDisplayNameUpdate(UpdateUserTitleDisplayNameResult result) {
     Debug.Log("UPDATED USERNAME!");
     leaderboardWindow.SetActive(true);
 }

 void OnError(PlayFabError error) {
     Debug.LogError("An error occurred: " + error.GenerateErrorReport());
     if (messageText != null) {
         messageText.text = error.ErrorMessage;
     }
 }

 public void SendLeaderboard(int score) {
     var request = new UpdatePlayerStatisticsRequest {
         Statistics = new List<StatisticUpdate> {
             new StatisticUpdate {
                 StatisticName = "Score Leaderboard",
                 Value = score
             }
         }
     };
     PlayFabClientAPI.UpdatePlayerStatistics(request, OnLeaderboardUpdate, OnError);
 }

 void OnLeaderboardUpdate(UpdatePlayerStatisticsResult result) {
     Debug.Log("Successful leaderboard sent");
 }

 public void GetLeaderboard() {
     var request = new GetLeaderboardRequest {
         StatisticName = "Score Leaderboard",
         StartPosition = 0,
         MaxResultsCount = 10
     };
     PlayFabClientAPI.GetLeaderboard(request, OnLeaderboardGet, OnError);
 }

 void OnLeaderboardGet(GetLeaderboardResult result) {

     foreach (Transform item in rowsParent) {
         Destroy(item.gameObject);
     }

     foreach (var item in result.Leaderboard) {
         GameObject newGo = Instantiate(rowPrefab, rowsParent);
         TMP_Text[] texts = newGo.GetComponentsInChildren<TMP_Text>();
         Debug.Log("Number of TMP_Text components: " + texts.Length);
         texts[0].text = (item.Position + 1).ToString();
         texts[1].text = item.DisplayName;
         texts[2].text = item.StatValue.ToString();

         Debug.Log(item.Position + " " + item.PlayFabId + " " + item.StatValue);
     }
 }

}

The main issue is in my "result.InfoResultPayload.PlayerProfile" which is always null. An explanation on how to fix this would be greatly appreciated.

Leaderboards and Statistics
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

·
Xiao Zha avatar image
Xiao Zha answered

I have tested your "Login" method, and it works fine. And if the player account has previously set a Display Name, it can be obtained through "result.InfoResultPayload.PlayerProfile.DisplayName" in your code. In addition, as PlayFab API doc: https://learn.microsoft.com/en-us/rest/api/playfab/client/authentication/login-with-custom-id?view=playfab-rest#getplayercombinedinforequestparams:~:text=Has%20no%20effect%20for%20a%20new%20player says, the “GetPlayerProfile” parameter has no effect for a new player. So, the “result.InfoResultPayload.PlayerProfile” will be null if the player account is a newly created account. In this case, you may call GetProfile API to get the player profile after you create the new account.

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.