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.
[Edited] Please refer to the following answer -- https://community.playfab.com/answers/51280/view.html.
Hey, can I get a sample code on how to implement this. I am a noobie :)
Your code snippet is basically correct, just need to modify the value of Keys to {}.
Answer by SethDu · Apr 02 at 07:11 AM
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=>{ });
Yeah so the code is working but the clothes are not loading up. Am I missing something?
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?
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()); }); } }
Answer by Roshan Singh · Apr 06 at 06:50 AM
Didn't find any thread on unity forums on this. I wanted to know if this is in any of the playfab examples.
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.
Yeah, I wanted to download the model files stored in Playfab and no I am not using Playfab CDN for now.
Yeah, I wanted to download the model files stored in Playfab and no I am not using Playfab CDN for now.
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.
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
Backup Player Data 1 Answer
Export player title data 1 Answer
Can i get event_log into game ? 1 Answer
Hi. Is it possible to use Facebook username for Playfab username? 1 Answer