I’m trying to implement item swapping in an inventory system using drag and drop. My plan is to detect the drag-drop event, identify the target slot based on the detected widget, and then swap the two items.
However, for some reason, some of the inventory slots don’t detect the drop at all. I thought the issue might be with the slots themselves, so I tried changing their visibility settings, creating entirely new inventory slots, and even tested it in a brand-new project — but the problem still persists.
I also verified the engine in case something was corrupted, but that didn’t help either.
Please, if anyone has any idea what’s going on, I would really appreciate your help. I’m stuck and running out of ideas.
Does it happen with all the slots or just some of them?
You can verify if On Drop is firing off by adding a print string to each slot. I would suggest you also feed it the slot index value, so you can verify you’ve hit the right slot. Let’s start with that.
If you’re getting the right information when On Drop is fired, please show how you handle your On Drop logic inside slot widget.
When the dragged button is dropped onto another button, the OnDrop function is triggered.
Through the Self reference passed from OnDragDetected, I compare the value of the button that initiated the drag with the value of the button it was dropped onto.
These values are associated with inventory slot indices, which were assigned using a ForEachLoop when creating the slots.
The goal was to pass the index values to the inventory and swap the values using the target index and the current index.
However…
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
When I drag item 14 onto slot 9, the OnDrop event is triggered correctly, and the values 9 and 14 are printed as expected.
However, when I drag item 9 onto slot 4, the drop target isn’t detected properly. Instead of detecting slot 4, it somehow detects slot 9 itself — resulting in the output 9 9.
At first, I didn’t realize that the drop wasn’t being detected correctly. But after inspecting with the Widget Reflector, I found that some buttons register the drop event properly, while others do not — as shown in the video I recorded.
The problem isn’t consistent either. It doesn’t only affect buttons that are directly above or below; sometimes left or right neighbors also fail to detect the drop.
I still haven’t figured out why this is happening.
Currently, I’m working around it by tracking the last mouse position and inferring the slot index manually.
But obviously, this isn’t an ideal or scalable solution.
I really want to understand why the drop detection fails in some cases.
I have been looking at your screenshot for good 15 minutes and nothing looks out of ordinary here, in fact it does look good. That made me re-watch the video over and over and something doesn’t look quite right but I’m having hard time pinning it down, partially because you’re dragging an empty slot (I did notice print strings this time). I did noticed it did work the first time (you get a green outline on a slot you’re hovering on), but then when you’re dragging (slot 9) it doesn’t produce that green outline, which makes me believe there is a problem with your visibility settings on the slot itself.
Here is my inventory slot widget for comparison.
[Thumbnail is Image]
[Quantity/SlotID are text]
My suggestion would be adding actual visual representation of items (hardcode few items into slots if you don’t have it setup yet), prevent dragging of empty slots and check if you’re dragging into the same slot index.
I also just noticed that you’re casting to this (I can’t make out the name, sorry). Could the problem be in here? Try using your original cast to WBP_Inventory_Slot.
Where does Cast Failed go? Try disconnecting that too!
Edit#2: If we’re unable to find what’s causing the issue, I might be able to send you a link to a project with working inventory, as shown in the video.
I think I’ve found the cause… and honestly, it’s a bit disappointing.
When using Create Drag Drop, I noticed that passing the image directly—or using self—caused the drop event not to be detected properly.
However, I found that if I create a new widget using Create Widget and pass that instead, the event is detected correctly.