- Home /
OnMouseUp() doesn't behave as documented
I know that this question has been asked before (for example here) but I didn't find a satisfactory answer; also, the answers provided in those threads used an older version of the documentation which has now changed.
Now to the issue at hand. Here's a quote from the MonoBehaviour:OnMouseUp() documentation:
Note that OnMouseUp is called even if the mouse is not over the same GUIElement or Collider as the has[sic] mouse has been pressed down on.
I find that this is not true. When I press the mouse button down next to my object with the OnMouseUp() script attached, then drag it in and release the button, nothing fires. Same thing when I drag from one object to another. In short, OnMouseUp() seems to behave the same way as OnMouseUpAsButton().
I checked the Issue Tracker but didn't find anything. Am I doing something wrong, is this a bug? Or is the documentation just wrong?
Definitely works as documented here. When you say "I press the mouse button down next to my object" it sounds like you're not actually clicking on the object. You have to click on the collider itself, not somewhere next to it.
Then let's put it another way. Let's say I have two objects, A and B. Object B has a script attached that contains On$$anonymous$$ouseUp(){...}. I move the cursor into object A, press and hold down the mouse button. Then I drag the cursor into Object B and release the mouse button; I would expect On$$anonymous$$ouseUp() to fire, as the mouse button went up while hovering over Object B, but it doesn't...so something is wrong here, even if it's just my understanding of the documentation.
EDIT: Argh, never$$anonymous$$d...it really was a misunderstanding. Thanks for the response and sorry for the confusion!
Answer by And0 · Jan 14, 2014 at 11:55 PM
Nevermind, I think it was really just a misunderstanding on my part. What the documentation means is that OnMouseUp() will still be fired even if the cursor has been moved outside of the original collider where the mouse button was pressed. So:
Click on Object A that has OnMouseUp script attached -> move cursor outside -> let go of button -> OnMouseUp() of Object A will still be called
I understood it as "when you let go of the button, the OnMouseUp() of the object that is currently under the cursor will be called", so:
Press and hold the mousebutton down on some random object -> move cursor over object B that has OnMouseUp attached -> let go of button -> OnMouseUp of object B will be called
Sorry about the confusion, guess I was just too tired.
Your answer
![](https://koobas.hobune.stream/wayback/20220613130444im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Anyone have a double-click script more reliable than mine? 3 Answers
OnMouseUP sometimes doesn't work 1 Answer
C# MOUSE EVENT TOGGLE 1 Answer
mouseup event does not work soon 0 Answers