Modifying an instance of a resource also modifies all other instances even though it is set to local

Godot Version

v4.2.1.stable.mono.official [b09f793f5]

Question

I’m trying to make an inventory system, and I have set up a few resources to do it:
an item resource, wich represents the items, a slotData resource which contains an item and an amount, and an inventoryData resource, which contains an array of slotDatas. Finally I have a inventory script, which holds the inventoryData resouce, and functions to act on it.

Now I have created an “item pickup” which has an inventory attached to it. When it is spawned I check wether there are other item pickups around, and if there are I want it to transfer its inventory to the first one it finds, and then destroy itself. This works, but when the inventory is transfered, this also affects the inventory of all other item pickups, despite the inventoryData resource being set to local in the editor.

These are the functions in the inventory script that I use to add and remove items:

    public void AddItem(Item item, int amount)
    {
        foreach (SlotData slot in inv.items)
        {
           if (slot.item == item && slot.amount < item.maxStack)
           {
               int spaceLeft = item.maxStack - slot.amount;
               int toAdd = Mathf.Min(amount, spaceLeft);
               slot.amount += toAdd;
               amount -= toAdd;
            
               if (amount <= 0) return;
           }
        }
 

        while(amount > 0)
        {
            SlotData newSlot = new SlotData();
            int toAdd = Mathf.Min(amount, item.maxStack);
            newSlot.item = item;
            newSlot.amount = toAdd;
            amount -= toAdd;

            inv.items.Add(newSlot);
        }
    }

    public void RemoveItem(int index, int amount)
    {
        if (index > inv.items.Count-1) return;
        SlotData slot = inv.items[index];
        slot.amount -= amount;
        if (slot.amount <= 0)
        {
            inv.items.RemoveAt(index);
        }

    }

And this is the function that I use to pool the pickups:

public void Pool()
    {
        if (pool)
        {
            PhysicsShapeQueryParameters3D query = new PhysicsShapeQueryParameters3D();
            query.Shape = new SphereShape3D();
            ((SphereShape3D)query.Shape).Radius = poolRadius;
            query.Transform = this.Transform;
            query.CollisionMask = (uint)Mathf.Pow(2, 31);

            var space = GetWorld3D().DirectSpaceState;
            var result = space.IntersectShape(query);
            foreach (var body in result)
            {
                Node bodyNode = (Node)body["collider"];
                
                if (bodyNode.IsInGroup("Item Drop") && (bodyNode != this))
                {
                    GD.Print("DROP FOUND");
                    ItemDrop drop = (ItemDrop)bodyNode;
                    if (!drop.pool) return;
                    foreach (SlotData slot in inventory.inv.items)
                    {
                        drop.inventory.AddItem(slot.item, slot.amount);
                    }
                    QueueFree();
                }
            }
        }

Any idea what might be causing this?