chest items get added to inventory

i’ve had this problem for some time with my chests

lets say i store 3 wood in the chest, close it and gather another 2, instead of having 2 in my inventory and 3 in the chest i have all 5 in my inventory

i followed a tutorial for both the inventory and chest system, but i changed the inventory system alot so i cant just redo the tutorial

i tried to fix this for some time, i think i found the thing that wrent wrong but i cant figure out how to fix it


heres all necessary code (unless im forgetting something) with notes added

https://hatebin.com/vlqyogayuy


heres what it looks like in action

So as understood, you have an inventory for your player and other for your chest. I think the best way of storing the items is using the Script in the chest that contains a List of items and other in the player, also with a list of items.

As you open the chest, you can access the List on the Chest object (via script) and transfer the items you want form it to the List on your player script. Then, when you close the chest, the items on it are independent but still there.

You can use

yourList1.Remove(item);

to remove at item from a list and then

yourList2.Add(item);

to add it to the other list.

thanks for helping @Tom4nt , but im not quite sure if i know what to do to change/fix it since im fairly new

maybe i should just skip the storage system for now and come back once i know more? although i feel like this shouldnt be too hard to fix, i just cant figure out how

the pot is weird, i tried to make it with stacks but it didnt really work so i had to make it like this

public class LootTable : MonoBehaviour
{
    public Loot[] loot;
    public List<Item> droppedItems = new List<Item>();
    private Item tmp;
    private bool rolled = false;
    public bool opened = false;

    private void Start()
    {
        droppedItems.Add(tmp);
    }

    public void AddLoot()
    {       
        if (!rolled)
        {
            RollLoot();
        }
        droppedItems.Remove(tmp);
        LootWindow.MyInstance.items.Clear();
        LootWindow.MyInstance.items.AddRange(droppedItems);
        LootWindow.MyInstance.itemCount = droppedItems.Count;     
        LootWindow.MyInstance.AddLoot();
    }

    public void RollLoot()
    {
        foreach (Loot item in loot)
        {

            int roll = Random.Range(0, 100);
            if(roll <= item.MyDropChance)
            {
                    droppedItems.Add(item.MyItem);             
            }
        }
        rolled = true;
    }
}

my item class is this

[CreateAssetMenu]
public abstract class Item : ScriptableObject, IMoveable, IDescribeable
{
    [HideInInspector]
    public SlotScript slot;
    public BagScript bag;
    public Sprite itemSprite;
    [SerializeField]
    private string itemName;
    [Range(1, 64)] public int maxStack = 64;
    [SerializeField]
    private Quality quality;

    public Sprite MyIcon
    {
        get
        {
            return itemSprite;
        }
    }

    public int MyMaxStack
    {
        get
        {
            return maxStack;
        }
    }

    public BagScript MyBag
    {
        get
        {
            return bag;
        }
        set
        {
            bag = value;
        }
    }

    public SlotScript MySlot
    {
        get
        {
            return slot;
        }
        set
        {
            slot = value;
        }
    }

    public Quality MyQuality { get => quality;}
    public string MyItemName { get => itemName;}

    public virtual string GetDescription()  
    {
        return string.Format("<color={0}>{1}</color>

", QualityColor.MyColors[MyQuality], MyItemName);
}

    public void Remove()
    {
       if(MySlot != null)
        {
            MySlot.RemoveItem(this);
        }
    }

}

with the items just inheriting from it (like wood (just fuel as of now) below)

[CreateAssetMenu(fileName = "Fuel", menuName = "Items/Fuel", order = 4)]
public class Fuel : Item
{
    [SerializeField]
    private bool isFuel;
    [SerializeField]
    private float fuel;

    public float MyFuel
    {
        get
        {
            return fuel;
        }
    }

    public bool IsFuel
    {
        get
        {
            return isFuel;
        }
    }
    public override string GetDescription()
    {
        return base.GetDescription() + string.Format("

Fuel amount: {0}", MyFuel);
}
}