There is a limitation of the ItemSlotCollectionView that stops AddItem working if called before the panel has been displayed. I am just posting this in case someone else hits this problem.
The ItemViewSlot component initializes the variable m_ItemViewSlotRestrictions in the Awake() method. If ItemSLotCollectionView.AddItem is called before the Awake gets called, then when it calls ItemViewSlot.CanContain, it will throw an error.
This can be fixed by calling Awake() at the beginning of the method ItemViewSlot.CanContain().
The ItemViewSlot component initializes the variable m_ItemViewSlotRestrictions in the Awake() method. If ItemSLotCollectionView.AddItem is called before the Awake gets called, then when it calls ItemViewSlot.CanContain, it will throw an error.
This can be fixed by calling Awake() at the beginning of the method ItemViewSlot.CanContain().
Code:
public bool CanContain(ItemInfo itemInfo)
{
// Initialise componenent if Awake han't been called yet.
// This can happen when inventory is added from code and the Panel has not yet been displayed
if (m_ItemViewSlotRestrictions == null) Awake();
for (int i = 0; i < m_ItemViewSlotRestrictions.Length; i++) {
if (m_ItemViewSlotRestrictions[i].CanContain(itemInfo) == false) { return false; }
}
return true;
}
Last edited: