Inventory Item can't get custom json data

Hello I am using Unity Gaming Services Economy and more specifically the inventory system. I am trying to get custom data from the inventory items but it doesn't work it just returns null.(code:

var inventoryResult = EconomyService.Instance.Configuration.GetInventoryItems();
       foreach (var item in inventoryResult)
        {
            var data = JsonConvert.DeserializeObject(item.CustomDataDeserializable.GetAsString());
            Debug.Log(data);

        }

)
I have checked if it was getting the object and it was. I didn't seem to find how to get custom data on the docs and had to rely on just description in the ide and some forums with limited info. Personally I find it baffling that unity doesn't document a important part of their service. Any help would be greatly appreciated.

1 Like

Hey mate, any luck with this? In the same boat over here. Feels like I'm flying blind with incomplete documentation. I appreciate what they're doing with the Economy system, I would just love some more detailed examples or implementation tutorials.


Hey, I contacted unity and they were able to answer my question and I asked them why it was absent in the docs and they said they would add it but I guess they never did. Any way this is the link to seemingly hidden documentation that fixed my problem
https://docs.unity.com/ugs/en-us/manual/economy/manual/SDK-configuration#Using_CustomData at least I think this was a while ago and after it was fixed it never really came back to mind.

1 Like

Legend! Thanks for your help here. For anyone else working on a similar problem, here's how I was able to call my inventory items and then sort them into the subcategory 'structures':

    public async void GetPurchasedStructures(){    
        await EconomyManager.instance.RefreshInventory();
        await EconomyService.Instance.Configuration.SyncConfigurationAsync();
        List<PlayersInventoryItem> inventory = EconomyManager.instance.inventoryResult.PlayersInventoryItems;   // all inventory items      
        List<PlayersInventoryItem> structures = new();  // inventory items listed as structures

        if (inventory == null)
        {
            Debug.Log("inventory is null.");
            return;
        }

        // sort through items to get structures
        foreach(var item in inventory){ 
            InventoryItemDefinition definition = item.GetItemDefinition();
            StructureCloudData data = definition.CustomDataDeserializable.GetAs<StructureCloudData>();
            if(data.type == "structure"){
                structures.Add(item);
                Debug.Log(item.InventoryItemId + " has been added to the purchased structure list"); ;
            }
        }

        Debug.Log("Purchased structure list:");
        foreach(var item in structures){
            Debug.Log(item.InventoryItemId);
        }
    }