question

My Game Studio avatar image
My Game Studio asked

How to set Key for GetUserData

Hi, I am trying to get Player Data by setting a key in GetUserData. However when I run the script, I got this "No user Data available" even I already set data in Player data. So how I get my high score from player data?

This is my script

public void GetUserData()
    {
        GetUserDataRequest request = new GetUserDataRequest()
        {
            PlayFabId = “my key”, // I already set this to my id
            Keys = null
        };

        PlayFabClientAPI.GetUserData(request,(result) => {
            Debug.Log("Got user data:");
            if ((result.Data == null) || (result.Data.Count == 0))
            {
                Debug.Log("No user data available");
            }
            else
            {
                foreach (var item in result.Data)
                {
                    Debug.Log(“  " + item.Key + " == " + item.Value.Value);
                }
            }
        }, (error) => {
            Debug.Log("Got error retrieving user data:");
            Debug.Log(error.ErrorMessage);
        });
    }

This is my script for set data

public void SetUserData()
    {
        UpdateUserDataRequest request = new UpdateUserDataRequest()
        {
            Data = new Dictionary<string, string>(){
                {"HighScore", "12000" },
                {"Level", "10"}
            }
        };

        PlayFabClientAPI.UpdateUserData(request, (result) =>
            {
                Debug.Log("Successfully updated user data");
            }, (error) =>
            {
                Debug.Log("Got error setting user data Ancestor to Arthur");
                Debug.Log(error.ErrorDetails);
            });
    }
10 |1200

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

Hamza Lazaar avatar image
Hamza Lazaar answered

Did you check that the User Data keys are successfully stored?

Do you get the "Successfully updated user data" log entry?

You can take a look at the User Data from the GameManager under "Players" tab, select a player then "Player Data".

Here is a shortcut (replace with proper values):

https://developer.playfab.com/Player/Details/{ {TitleID}}?playerId={ {PlayFabID}}#data

But for score, why don't you use User Statistics instead?

10 |1200

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

brendan avatar image
brendan answered

In addition to Hamza's questions, what is the PlayFab ID of the user in your title, and what result do you get querying for the User Data in Postman?

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.