Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug InventoryItemDefinition CustomDataDeserializable returns empty

Discussion in 'Economy' started by Lucas-Orqual, Jun 12, 2023.

  1. Lucas-Orqual

    Lucas-Orqual

    Joined:
    May 16, 2023
    Posts:
    1
    Hi,

    I'm using Unity 2022.3.1f and Economy 3.1.2

    I have an inventory Item named SWORD with a custom data :
    {
    "rarity": "purple"
    }

    The following code is based on the Unity Gaming Service Samples, more precisely the Virtual Shop.

    The CustomDataDeserializable in my project return an empty string even though when I tested it in the project samples it works. I've also tested the few lines in the documentation which returns also an empty string.

    Just to be sure, i've also tested the InstanceDataDeserializable of an Item and this one works.

    Code (CSharp):
    1.     public async void InitEconomy()
    2.     {
    3.         await EconomyService.Instance.Configuration.SyncConfigurationAsync();
    4.  
    5.         var addressablesLoadAsyncData = new AddressablesLoadAsyncData();
    6.  
    7.         AddAddressablesItemTasks(EconomyService.Instance.Configuration.GetInventoryItems(), addressablesLoadAsyncData);
    8.     }
    9.  
    10. void AddAddressablesItemTasks(List<InventoryItemDefinition> inventoryItemDefinitions,
    11.     AddressablesLoadAsyncData addressablesLoadData)
    12.     {
    13.         if (inventoryItemDefinitions == null)
    14.         {
    15.             return;
    16.         }
    17.  
    18.         foreach (var inventoryItemDefinition in inventoryItemDefinitions)
    19.         {
    20.             Debug.Log(inventoryItemDefinition.Name);
    21.             Debug.Log(inventoryItemDefinition.CustomDataDeserializable.GetAsString());
    22.             if (inventoryItemDefinition.CustomDataDeserializable.GetAs<Dictionary<string, string>>() is { } customData
    23.                 && customData.TryGetValue("rarity", out var rarityValue))
    24.             {
    25.                 addressablesLoadData.Add(inventoryItemDefinition.Id, rarityValue);
    26.                 Debug.Log(rarityValue);
    27.             }
    28.         }
    29.     }
     
  2. Shaun-Peoples

    Shaun-Peoples

    Joined:
    Feb 26, 2013
    Posts:
    24
    This seems like it could be throwing an exception, which is what I ran into with the CustomDataDeserializable.GetAs. Put a try/catch block in there to get info on the exception.
     
  3. hgopi

    hgopi

    Joined:
    Nov 12, 2019
    Posts:
    6
    I used the same kind of code and it is working fine for me. As mentioned by Shaun-Peoples, you might get other issues in the code. Also check you published your changes and set the correct environment.