/// <summary> /// Can be called client and server side to free up the cached /// slots in this storage. Should be called when storage is going to be destroyed or /// will be no longer known by the client. On server side, also destroys all the items in the slot. /// </summary> /// <param name="storageToFree"></param> public static void Free(ItemStorage storageToFree) { if (CustomNetworkManager.Instance != null && CustomNetworkManager.Instance._isServer) { //destroy all items in the slots foreach (var slot in storageToFree.GetItemSlots()) { if (slot.Item != null) { Inventory.ServerDespawn(slot); } } } if (storageToFree.GetComponentInParent <NetworkIdentity>()) { var instanceID = storageToFree.GetComponentInParent <NetworkIdentity>().GetInstanceID(); slots.TryGetValue(instanceID, out var dict); if (dict != null) { dict.Clear(); slots.Remove(instanceID); } } }