How to prevent items from overlapping in inventory?

Hello friends. I made an inventory system. I can put items wherever I want. But I don’t want them to be on top of each other. I’ve been thinking about this for 2 days and still haven’t found an idea. I tried something but it didn’t work. Do you have any ideas? I would be very happy if you could tell me.

I used characterbody for items and area for slots. The text may be a little incorrect, I mostly used google translate.(Godot4)

If you are curious about the codes, here they are:

You have to remember which solts are “taken” inside an array or dictionary and then check if you can place a new item there

I tried that but it didn’t work. Here’s what I did:

I created a global variable for Slot1. For example, when the sword is touch up, If slot1 is not full, it will be placed there and slot1 is full will be true . But this caused the sword not to be placed there. Here it is:

İf! slot1full:
position = Vector2()
slot1full = true

well it has to be initialized with the value false, and when you move the sword again you have to set the value again to false