Change Item Collection ID of Item Slot Collection View during runtime

SD GAMES

New member
Hi, is it possible to change Item Collection ID of Item Slot Collection View during runtime and get the new slot collection to populate the grid?
I managed to change it via code but the items don't appear on the grid until I close and open the panel again.

I'm using the following method in the ItemSlotCollectionView script
C#:
public void ChangeItemCollectionId(string newID)
        {
            m_ItemCollectionID = newID;
            OnInventoryChanged(m_Inventory, m_Inventory);
        }
 
You are missing a Draw call... but that's my fault it should be doing it by default when changing inventory.

In the base class "ItemViewSlotsContainerBase" replace the function with this:
Code:
/// <summary>
/// A new Inventory was set.
/// </summary>
protected virtual void OnInventoryChanged(Inventory previousInventory, Inventory newInventory)
{
    Draw();
}

Then in the "ItemSlotCollectionView" override call the base class at the end:
Code:
/// <summary>
/// A new Inventory was set.
/// </summary>
protected override void OnInventoryChanged(Inventory previousInventory, Inventory newInventory)
{
    if (m_Inventory == null) {
        m_ItemSlotCollection = null;
        return;
    }
    m_ItemSlotCollection = m_Inventory.GetItemCollection(m_ItemCollectionID) as ItemSlotCollection;
    if (m_ItemSlotCollection == null) {
        Debug.LogError($"The inventory '{m_Inventory}' does not contain an item slot collection for the ID provided in the ItemSlotCollectionView", gameObject);
        m_Inventory = null;
        return;
    }
    if (m_ItemSlotSet != m_ItemSlotCollection.ItemSlotSet) {
        Debug.LogError($"The item slot collection '{m_ItemSlotCollection}' has an Item Slot Set '{m_ItemSlotCollection.ItemSlotSet}' " +
                       $"which does not match with the Item Slot Set '{m_ItemSlotSet}' provided in the ItemSlotCollectionView", gameObject);
        m_Inventory = null;
        m_ItemSlotCollection = null;
        return;
    }
    
    base.OnInventoryChanged(previousInventory, newInventory);
}

With that your UI should update when you call the

I've also added your function in the ItemSlotCollectionView.
Code:
/// <summary>
/// Change the ItemCollection ID.
/// </summary>
/// <param name="newID">The new Item Collection ID to monitor.</param>
public void ChangeItemCollectionId(string newID)
{
    m_ItemCollectionID = newID;
    OnInventoryChanged(m_Inventory, m_Inventory);
}

All this will be available in a future update.
I hope that helps
 
Top