On Click () doesn't fire if you move the mouse before you release the mouse button [SOLVED]

If I click down on a button and move the mouse cursor 1 pixel and release the button doesn’t register the click, even if my mouse cursor is still over the button, it only fires if I release on the exact pixel I clicked on. It makes the default On Click () event which you have access to in the inspector for the Button component completely useless and basically a “noob trap” (something to trick beginners into making games with poor usability).

Surely this can’t be intended? The expected, and in my opinion correct behavior, is to not fire the On Click () if you move the mouse outside the button before you release, this is how every single other application does it.

Edit: You can see that it works this way if you have transitions enabled for the button. It clearly goes from the “pressed” state to the “highlight” state when you move the cursor. Completely wrong in my opinion.

Edit 2: A lot of what I say here is false, Unity does it correctly. Read my next reply to see what was causing issues for me in my project.The internet has thought me that stating something as fact and getting someone to prove you wrong is a more efficient way of getting help than asking for it. :stuck_out_tongue:

Unity does it like that.

Try this:

  • Start your game.
  • From the scene, select the GameObject with the EventSystem component.
  • Information about input should be presented at the bottom of the inspector.
  • Now press the button, “pointerEnter” and “pointerPress” should now reference to your button.
  • Move your mouse a bit and check whether “pointerEnter” is changed to reference something else.

If “pointerEnter” no longer has your button, something else has captured the input.

It had been this way in my project for months and I never bothered to look at it nor write about it until now, but after you replied I couldn’t replicate it and it worked like it should. But I had refactored pretty much my entire project 2-3 times in that time so it was a bit hard to say what had changed.

I debugged it for a bit now and realized that it was the script I had previously written to allow me to drag my panels around that interfered with the buttons. I saw it thanks to your tip about the EventSystem component. The draggable panel script was changing the pressed event into a drag event when I moved the mouse cursor on a button because the script was on a parent of the buttons.

Thanks a lot. :slight_smile: