Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • General Discussion /
avatar image
Question by Roshan Singh · Mar 25 at 06:14 PM · Player Data

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.

jhjhjhj.png (173.2 kB)
fdfdukttuktuk.png (25.9 kB)
Comment

People who like this

0 Show 4
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sarah Zhang ♦ · Mar 26 at 02:49 AM 0
Share

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

avatar image Roshan Singh Sarah Zhang ♦ · Mar 26 at 07:41 AM 0
Share

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

avatar image Sarah Zhang ♦ Roshan Singh · Mar 30 at 01:56 AM 0
Share

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

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

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=>{ });
Comment

People who like this

0 Show 5 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Roshan Singh · Apr 02 at 09:02 AM 0
Share

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

capturelkokok.png (488.4 kB)
avatar image Sarah Zhang ♦ Roshan Singh · Apr 05 at 09:21 AM 0
Share

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?

avatar image Roshan Singh Sarah Zhang ♦ · Apr 05 at 01:59 PM 0
Share

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());
    });
}
}



Show more comments
avatar image

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.

Comment

People who like this

0 Show 6 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sarah Zhang ♦ · Apr 07 at 01:59 AM 0
Share

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.

avatar image Roshan Singh Sarah Zhang ♦ · Apr 07 at 04:07 AM 0
Share

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

avatar image Roshan Singh · Apr 07 at 04:07 AM 0
Share

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

avatar image Sarah Zhang ♦ Roshan Singh · Apr 07 at 06:46 AM 0
Share

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.

avatar image Roshan Singh Sarah Zhang ♦ · Apr 08 at 07:29 AM 0
Share

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

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    3 People are following this question.

    avatar image avatar image avatar image

    Related Questions

    Backup Player Data 1 Answer

    Export player title data 1 Answer

    Can i get event_log into game ? 1 Answer

    Admin panel in unity, to modify the statistics of the player you want / choose,Modify player data in a unit panel 1 Answer

    Hi. Is it possible to use Facebook username for Playfab username? 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges