Is the Input System not working properly? (OSX Unity Editor 5.4.1)
So, I've tried with several methods of Input Class, and any of them seems to lose a held button after a couple of time. I've been searching for something that explains that on my project/scene but have found nothing.
Symple putting Input.anyKey
or Input.GetMouseButton(0)
or something like that (as the first one already negates the others), on an Update() will show the problem.
void Update() {
if (Input.anyKey) {
print("Button being held");
}
}
//Will print only for a couple of seconds only.
//The object holding the script is not being deactivated(prints false outside the if statement).
I just want to capture the mouse being held down for a long time, dragging some objects(and I want using the Input System, because I'll then switch to touch events), but after 1 ~ 5 seconds the event just loses the button, and keeps returning false, even the Input.GetMouseButtonUp(0) event (for example) is not called after that.
Is anyone also having this problem?
Answer by Atair · Nov 12, 2016 at 11:39 AM
Just had the same problem (osx, normal mouse, but magic trackpad).
Anyway - the Solution:
Edit > Project Settings > Editor: Turn off the Unity Remote
Now the mouse works fine (at least for me)
Apparently that was the problem for me too... After a few hours going crazy by creating test scenes and comparing to the main scene, the problem was gone I couldn't figure out what was causing it. Then I saw your answer and I realized and I was using Unity Remote at the time.
Answer by Landern · Oct 26, 2016 at 01:13 PM
I'm using a real mouse(no magic mouse business, nor track pad or anything like that) and i can't reproduce your issue.
The script i used to test without anything super complicated, just a clean scene, empty gameobject with the below script attached. Attached is also a screen shot of the Unity Editor console.
using UnityEngine;
public class Test : MonoBehaviour
{
float heldTime = 0.0f;
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
heldTime += Time.deltaTime;
}
if (Input.GetMouseButtonUp(0))
{
Debug.Log("Mouse Released, resetting held time to 0.0f.");
heldTime = 0.0f;
}
Debug.Log("Mouse Held For: " + heldTime.ToString() + " Seconds");
}
}
If something as simple as this isn't working, i would check out the implementation or the mouse/device drivers. Maybe use another device. Also perhaps something something else is running that might capture the mouse down event at a system level and reset it. Just some thoughts.