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.