GetMouseButtonDown is inconsistent

Hi all!

For short: I try to move a object with a boxcollider. To do this, I check in the Update function, wether the left Mouse Button is pressed (GetMouseButtonDown), released (GetMouseButtonUp) or hold (GetMouseButton).

On GetMouseButtonDown, I make a RayCast and if it hits the collider of my object, set “modelHit” to true and disable the collider:

On GetMouseButton I check, if “modelHit” is true, and then move the object to the position of the mouse.

On GetMouseButtonUp I re-enable the collider, and set “modelHit” to false.

Now I have the problem, sometimes wether GetMouseButtonDown is ignored, or GetMouseButtonUp is set to true when it shouldn’t. To make this more visible, I started to Log when the Button is pressed & Released. In the console I can see something like this:





[At this point, the mouse button is currently hold!]


[And now released]

Could you give me an explanation why this is happening? How may I solve this issue? As I said: I check this in Update, as descriped in the docs.

Thanks for help!

This sounds like a broken mouse ^^. My mouse is actually broken for several years now. The right mouse button doesn’t snap properly and sometimes looses “contact” even though i still hold the button down. Very annoying when dragging things with the right mouse button…

Another possibility is that you have either another hardware that emulates mouse actions (like one of those G15 / G19 keyboards or a mouse with macro support), or there is some kind of software running that emulates mouse actions (Autohotkey for example).

Personally i never had any issues detecting mouse events besides the things i’ve already mentioned (for example forgetting to shut down an AHK script after playing minecraft ^^).

What you can try to debug this issue is to log the actual mouse messages that are send to your application. You can simply use OnGUI:

void OnGUI()
    Event e = Event.current;
    if (e.type == EventType.MouseDown)
        Debug.Log("Mouse Down " + e.button);
    else if (e.type == EventType.MouseUp)
        Debug.Log("Mouse Up " + e.button);

If this shows the same behaviour it’s most likely a hardware or third party software problem.