question

Roshan Singh avatar image
Roshan Singh asked

Can't get Player Data.,Can't Get Player data

I used the code given in the quickstart get and set player data. Set player data is working and game is sending data to Playfab but when I try to get player data. It shows in the console "Got player data" but then an error comes

KeyNotFoundException: The given key was not present in the dictionary. System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <fb001e01371b4adca20013e0ac763896>:0) PlayFabRegister+<>c.<GetUserData>b__35_0 (PlayFab.ClientModels.GetUserDataResult result) (at Assets/SignIn/Scripts/PlayFabRegister.cs:257) 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:247) UnityEngine.Debug:LogException(Exception) PlayFab.Internal.PlayFabUnityHttp:OnResponse(String, CallRequestContainer) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:251) PlayFab.Internal.<Post>d__12:MoveNext() (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:190)

Here's the get user data code.

,

KeyNotFoundException: The given key was not present in the dictionary.

Player Data
jhjhjhj.png (169.1 KiB)
fdfdukttuktuk.png (25.3 KiB)
4 comments
10 |1200

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

Sarah Zhang avatar image Sarah Zhang commented ·

[Edited] Please refer to the following answer -- https://community.playfab.com/answers/51280/view.html.

0 Likes 0 ·
Roshan Singh avatar image Roshan Singh Sarah Zhang commented ·

Hey, can I get a sample code on how to implement this. I am a noobie :)

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Roshan Singh commented ·

Your code snippet is basically correct, just need to modify the value of Keys to {}.

0 Likes 0 ·
Show more comments
Seth Du avatar image
Seth Du answered

According to your information, the API call should be successful. The issue is not at the API request because the error indicates the dictionary doesn't contains the specified keys. You are doing great at the if statement, where you are using ContainsKey keyword to handle the non-existing case. However, in the else statement, you are directly referring "MaleRobe" key of result.Data, there is no guarantee for this. Try to implement ContainsKey here as well.

For the testing purpose, you should use foreach loop to printout the result.Data to see the details. Please note that the variable type in the result and always refer to the document -- Player Data Management - Get User Data (PlayFab Client) | Microsoft Docs.

Here is a sample:

PlayFabClientAPI.GetUserData(new GetUserDataRequest {},
    success=> {
        if (success.Data.ContainsKey("preferences"))
        {
            print(success.Data["preferences"].Value);
        }
        if (success.Data.ContainsKey("progress"))
        {
            print(success.Data["progress"].Value);
        }
        foreach (var item in success.Data)
        {
            print(item.Value.Value);
        }
    },
    failed=>{ });
5 comments
10 |1200

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

Roshan Singh avatar image Roshan Singh commented ·

Yeah so the code is working but the clothes are not loading up. Am I missing something?

0 Likes 0 ·
capturelkokok.png (477.0 KiB)
Sarah Zhang avatar image Sarah Zhang Roshan Singh commented ·

Apologies, for your case, keeping the Keys as null is OK. Glad to see the answer from Seth solved your question.

For the question about cloth loading, have you written the code to display the cloth 3D models? In your screenshot, we didn't see the code snippet that used to load the cloth models. Could you please provide the corresponding code for us to analyze?

0 Likes 0 ·
Roshan Singh avatar image Roshan Singh Sarah Zhang commented ·

I didn't know that a code is required to load 3d models. I thought this code was enough.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class userdata : MonoBehaviour
{
   
 public void GetUserData(string myPlayFabeId) {
    PlayFabClientAPI.GetUserData(new GetUserDataRequest() {
        PlayFabId = myPlayFabeId,
        Keys = null
    }, result => {
        Debug.Log("Got user data:");
        if (result.Data == null || !result.Data.ContainsKey("TORSO")) Debug.Log("No TORSO");
        else Debug.Log("TORSO: "+result.Data.ContainsKey("TORSO"));
    }, (error) => {
        Debug.Log("Got error retrieving user data:");
        Debug.Log(error.GenerateErrorReport());
    });
}
}



0 Likes 0 ·
Show more comments
Roshan Singh avatar image
Roshan Singh answered

Didn't find any thread on unity forums on this. I wanted to know if this is in any of the playfab examples.

6 comments
10 |1200

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

Sarah Zhang avatar image Sarah Zhang commented ·

Do you mean you want to display the local clothes models file in the scene? Or you want to download the model files stored in PlayFab? If you want to download the model file, could you please provide more details? For example, do you use PlayFab CDN?

If you only want to display or load a local model file in the Unity scene, it’s entirely Unity’s job. You can't use any PlayFab API to display a 3D model, PlayFab API can only return text. After getting the value of the user data, you need to use Unity Scripting API to display the model. For instance, you can refer to this manual to instantiate Prefabs at run time.

You can find the PlayFab samples in this documentation -- Recipes and samples - PlayFab | Microsoft Docs.

0 Likes 0 ·
Roshan Singh avatar image Roshan Singh Sarah Zhang commented ·

Yeah, I wanted to download the model files stored in Playfab and no I am not using Playfab CDN for now.

0 Likes 0 ·
Roshan Singh avatar image Roshan Singh commented ·

Yeah, I wanted to download the model files stored in Playfab and no I am not using Playfab CDN for now.

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Roshan Singh commented ·

So, how did you store them? Do you store them as the Entity Files?

If so, you can refer to this documentation -- Entity files - PlayFab | Microsoft Docs to download them.

0 Likes 0 ·
Roshan Singh avatar image Roshan Singh Sarah Zhang commented ·

We used to store them locally but now we want to store it in the server. Could you please tell me the difference between CDN and Entity files. Thank you

0 Likes 0 ·
Show more comments

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.