question

getplaybrasil avatar image
getplaybrasil asked

Set DisplayName in textfield problems Object reference not set to an instance of an object

Hi, Folks. I'm trying to set the displayname default value directly from the API, the debug log correctly informs the username. But when I believe that it should fill the textfield it generates an error, could someone guide me to implement this function it would be very important for me I've been trying since yesterday, but without success. Any help is welcome, thanks in advance.

Console error image --->

    #region DisplayName

   public  void PlayerData(string playFabId)
    {
        PlayFabClientAPI.GetPlayerProfile(new GetPlayerProfileRequest()
        {
            PlayFabId = playFabId,
            ProfileConstraints = new PlayerProfileViewConstraints()
            {
                ShowDisplayName = true
            }


        },
  (result) =>
  {


      Debug.Log("The player's DisplayName profile data is: " + result.PlayerProfile.DisplayName);
      playerNameText.text = result.PlayerProfile.DisplayName;


  },
(error) =>
{
    Debug.LogError(error.GenerateErrorReport());
});
    }


    #endregion DisplayName
Player Data
erro-console.png (138.9 KiB)
codigo.png (19.8 KiB)
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.

getplaybrasil avatar image getplaybrasil commented ·

Error log->

NullReferenceException: Object reference not set to an instance of an object
PlayFabController.<PlayerData>b__29_0 (PlayFab.ClientModels.GetPlayerProfileResult result) (at Assets/Scripts/PlayFabController.cs:232)
PlayFab.Internal.PlayFabHttp+<>c__DisplayClass23_0`1[TResult].<_MakeApiCall>b__1 () (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabHTTP.cs:215)
PlayFab.Internal.PlayFabUnityHttp.OnResponse (System.String response, PlayFab.Internal.CallRequestContainer reqContainer) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:207)
UnityEngine.Debug:LogException(Exception)
PlayFab.Internal.PlayFabUnityHttp:OnResponse(String, CallRequestContainer) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:211)
PlayFab.Internal.<Post>d__12:MoveNext() (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:159)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
0 Likes 0 ·

1 Answer

·
Seth Du avatar image
Seth Du answered

Line 232 is to assign the value to playerNameText.text, meanwhile it cannot be determined if result.PlayerProfile.DisplayName is initialized with a proper value. You need to add a value check (Null check) sentence before the assignment.

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.