question

Scott Browne avatar image
Scott Browne asked

GetUserData return function always null

Why does a return function like this always turn null? Are turn functions returning before the results are queried? If so how would you go about making a function that returns the values after the query?

 public string GetUserNameData(string myPlayFabeId, string slot)
    {       
        string tempName = "";
        PlayFabClientAPI.GetUserData(new GetUserDataRequest()
        {
            PlayFabId = myPlayFabeId,
            Keys = null
        }, result => {
            Debug.Log("Got user data:");
            if (result.Data == null || !result.Data.ContainsKey(slot + "_" + "PlayerName")) 
            {
                tempName = "Empty Slot";
                Debug.Log("No Name"); 


            }
            else
            {
                tempName = result.Data[slot + "_" + "PlayerName"].Value;


                Debug.Log("PlayerName: " + result.Data[slot + "_" + "PlayerName"].Value);
            }
        }, (error) => {
            Debug.Log("Got error retrieving user data:");
            Debug.Log(error.GenerateErrorReport());
        });
        Debug.Log(slot + "___tempName : "  + tempName);
        return tempName;
    }
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

·
Rick Chen avatar image
Rick Chen answered

The GetUserData API retrieves the user data from the server, then return to your callback function. Please double check if your user actually has that key on Game Manager.

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.