Trying to get specific custom data from specific items in the local users inventory.
Do not know if I am going at this the wrong way or if it can not be done.
Code:
List<ItemInstance> Items = new List<ItemInstance>();
GetUserInventoryRequest InventoryR = new GetUserInventoryRequest();
PlayFabClientAPI.GetUserInventory(InventoryR,
result => { Items = result.Inventory; },
error => { Debug.Log(error.ErrorMessage); });
Answer by madsfknudsen · Jul 06, 2019 at 07:27 PM
Error when calling result.Inventory[0].CustomData["HasBeenCreated"].
HasBeenCreated is one of the customdata keys and has a string value of "false".
NullReferenceException: Object reference not set to an instance of an object CharacterCreator.<Start>b__5_2 (PlayFab.ClientModels.GetUserInventoryResult result) (at Assets/Scripts/CharacterCreation/CharacterCreator.cs:50) PlayFab.Internal.PlayFabHttp+<>c__DisplayClass23_0`1[TResult].<_MakeApiCall>b__1 () (at Assets/Extensions/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabHTTP.cs:218) PlayFab.Internal.PlayFabUnityHttp.OnResponse (System.String response, PlayFab.Internal.CallRequestContainer reqContainer) (at Assets/Extensions/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:246) UnityEngine.Debug:LogException(Exception) PlayFab.Internal.PlayFabUnityHttp:OnResponse(String, CallRequestContainer) (at Assets/Extensions/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:250) PlayFab.Internal.<Post>d__12:MoveNext() (at Assets/Extensions/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:189) UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
Try this:
PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), result => { Debug.Log (result.ToJson()); }, error => { Debug.Log ("Error: " + error.GenerateErrorReport()); });
Look through the returned JSON data that gets logged if it's successful, and make sure it is returning the inventory correctly.
Answer by SethDu · Jul 08, 2019 at 06:32 AM
According to the error message, there is a high possibility that the instance doesn’t have this property in the Custom Data. To diagnose it, first is to check if the player owns this item instance in the Game Manager. In addition, manually check the custom data of this item instance. Second, in your C# codes, try to use foreach to print out all the needed information.
Answer by Evil Twin · Jun 02 at 07:14 PM
The correct answer is that Playfab doesn't return any CustomData with players' inventory items. It's counterintuitive and doesn't make sense right? But there ya go. It's intentionally null :
https://community.playfab.com/questions/3958/empty-custom-data-for-item-instances.html
Setting player data through ue4 blueprints 1 Answer
Playfab Player Data Fields ? 1 Answer
How do i get the player inventory from javascript? 1 Answer
Questions on storing a list of strings on PlayFab to be accessed by all users, or similar methods 2 Answers
How to print custom data with key value pairs of certain items from server side in C#? 1 Answer