- Home /
Unity sometimes misses Mouse Button Release
currently running into a weird issue. Imagine you have this code:
private bool Mouse0Pressed = false;
public void Update()
{
if(Input.GetMouseButtonDown(0))
{
Mouse0Pressed = true;
}
if(Input.GetMouseButtonUp(0))
{
Mouse0Pressed = false;
}
}
In some random situations ( 1 out of ~100) Mouse0Pressed
stays true
after i release the mouse button. Interesting enough Input.GetMouseButton(0)
also returns true in that case which implies to me that Unity missed the MouseButtonUp event. Both states reset to the correct value if i do another click but stay true
until then.
Does anyone know if this is a known issue? could not find any info on that. Kind of lost in that regard.
Answer by Vivien_Lynn · Sep 22, 2021 at 11:36 AM
My first instinct would be to monitor your mouse with some third party sofware, to see if it might be an hardware issue.
Edit, the following is apparently wrong. Read @rage_co o comment below for more information:
This is just an assumption, but I think Unity actually checks if your mouse is pressed or not. If it was pressed, and is not anymore, then Unity calls the "MouseUP once.
This means, even if Unity would "miss" the MouseUP in one particular frame, it does not matter, since it would just check again in the next frame.
If this is true, then it must be your mouse that still sends the input.
its actually the opposite, unity and many other engines check for inputs through the down actions and up actions, which means that the computer has no way to know if the button is currently pressed......you can do this experiment, hold down a key in your project or a game and disable the keyboard, the input would still be considered as pressed, until you turn your keyboard back on and repress the button and then let it go.....can also be tried with a mouse, so it can be a hardware problem, about the mouse forgetting to send the up signal
it is not a hardware issue as this behaviour is reproduceable on different PCs and i highly doubt that all of them have issues with their mouses.
so is this code all of it? i mean i tried it and it works a 100% fine
Your answer
Follow this Question
Related Questions
Unity 4.6.3f1 bug or normal behaviour? MouseButtonDown cancelled/ ignored by key press 0 Answers
Disable mouse input and cursor in game 2 Answers
Unity Web Player does not respond to mouse clicks 1 Answer
button.Select() and alternatives don't seem to work when called via new input system 1 Answer
Mouse click is detected twice 1 Answer