OnPointerUp() is called when I move the mouse outside the element I clicked down on and never again

I just refactored my inventory system so that the pointer logic is added to each inventory slot rather to the global UI. I thought this was a neater way of doing it, but now I’m unable to replicate the functionality I had because the event system doesn’t work like I thought it did or how I feel it should.

Let’s say I have 2 slots in my inventory and there’s an item in slot 1. I click down on the item and I pick it up, then I drag the item with the mouse button held down over to slot 2 and release the mouse button, but nothing happens, my OnPointerUp() code isn’t fired.

Then I debugged this and noticed that OnPointerUp() is fired when I drag the mouse out of slot 1 and never again until I click the mouse button again.

Why? Why is OnPointerUp() fired when I’m not even releasing the mouse button? And why isn’t it called when I actually release the mouse button? This is so frustrating. It feels like the only way you can know how these things work is by learning all the caveats and gotchas.

So I guess OnPointerUp() is only called for the same element you actually clicked on? Is there any way for me to remedy my refactor or must I revert everything to how it was? Everything became so much neater this way because the slot component handled everything itself rather than some global UI controller handling the slot functionality, but if it doesn’t allow me to do what I want then that doesn’t matter.

Okay, that solved itself before I got more frustrated. :stuck_out_tongue:

OnDrop() did exactly what I wanted and allowed me to simplify my code even more because I don’t have to check if the slot is the same slot I started dragging from.

But I still think what I wrote about in the initial post is either bugged or poorly implemented.

Edit: Nvm, I still have to check if it’s the same slot because OnDrop() is called for the same slot if I move the mouse inside the slot, but at least it works now and the same way it did before the refactor.

1 Like