question

madsfknudsen avatar image
madsfknudsen asked

Getting CustomData from specific user inventory items

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

dataPlayer InventoryCharacter Data
10 |1200

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

brandon@uprootstudios.com avatar image
brandon@uprootstudios.com answered

What errors are you getting?

10 |1200

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

madsfknudsen avatar image
madsfknudsen answered

@Brandon Phillips

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)

1 comment
10 |1200

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

brandon@uprootstudios.com avatar image brandon@uprootstudios.com commented ·

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.

0 Likes 0 ·
Seth Du avatar image
Seth Du answered

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.

1 comment
10 |1200

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

franklinchen avatar image franklinchen commented ·

Hi @madsfknudsen, any updates?

0 Likes 0 ·
Good Guy avatar image
Good Guy answered

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

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.