Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Unity 2022.2 is now available as the latest Tech release.
    Dismiss Notice
  3. We are making some changes to the DOTS forums.
    Dismiss Notice
  4. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice


Discussion in 'Game Foundation' started by VektaCo, Jan 30, 2021.

  1. VektaCo


    Sep 30, 2019
    Does this function work? There are no examples online or in the samples.

    This always returns null
    Code (CSharp):
    1. GameFoundationSdk.inventory.FindItem(_ItemID);
    whereas doing it this way works, but is a lot of extra steps.

    Code (CSharp):
    1. InventoryItemDefinition Item = GameFoundationSdk.catalog.Find<InventoryItemDefinition>(_itemID);
    3. List<InventoryItem> m_InventoryItems = new List<InventoryItem>();
    4.    GameFoundationSdk.inventory.FindItems(Item, m_InventoryItems);      
    6. if (m_InventoryItems.Count > 0)
    7. {
    8.       return m_InventoryItems[0];
    9. }
  2. tony_c-unity3d


    Unity Technologies

    Jul 18, 2019
    Hi @VektaCo ,

    Apologies for the confusion, but the FindItem method in your code snippet uses the item id which is a unique GUID associated with the item, not the item definition key. To find all items with a specified definition, you'll need to use the 2nd approach to first find the inventory item definition based on the inventory item definition key THEN use that definition to find all items created using that definition.

    To elaborate, these inventory item id's are generated automatically and may look something like: "a66b0bfb-8174-4a95-a594-4faa78ab06e0" whereas the inventory item definition key is set by you in the editor and can be anything. For example, in our sample/01_InventoryBasics catalog, there are 2 inventory item definitions with keys: "apple" and "orange". These keys can be passed into catalog.Find<> (as your 2nd snippet demonstrates where _itemID is the inventory item definition key) to retrieve the associated inventory item definition.

    Hope this helps. If you have any other questions, please let me know. Thanks and have a great weekend!
    erika_d, VektaCo and saskenergy like this.