Just working with the new input system and I’ve found some issues with touch input. For some reason TouchPhase.Began doesn’t always happen, is there some reason why that would happen?
Maybe the update?
private void Awake()
{
UnityEngine.InputSystem.EnhancedTouch.EnhancedTouchSupport.Enable();
}
public void Update()
{
foreach (var finger in UnityEngine.InputSystem.EnhancedTouch.Touch.activeFingers)
{
Debug.Log( finger.currentTouch.phase+" <<");
if (finger.currentTouch.phase == UnityEngine.InputSystem.TouchPhase.Began)
{
Beep();
}
}
}
Also for some weird reason, if I build to the iPad TouchPhase.Began fires constantly during a press.
Oh I should say this is on input system 1.0.0 and Unity 2019.4
Well it looks like the began phase is unreliable even though the touch count changes.
I moved my ‘Began’ code into touch phase - Began, Moved and Stationary with a bunch of checks to make sure it only runs once before any ‘moved’ stuff. Bit of a shame it feels pretty hacky.
Hi Daniel, would you mind filing a ticket with the bug reporter (Help >> Report a Bug… in the Unity editor)? Sounds like there’s potentially a separate thing with Windows touch input that needs looking at.
Same. Some touches don’t trigger Began, but Input Debugger show Began phase.
Device: LG G2
Unity: 2020.2.1f1, 2020.3.12f1
Package: Input System 1.1.0-preview.3 (LTS doesn’t support newer package)
private void Update()
{
var touch = Touchscreen.current?.primaryTouch;
if (touch == null)
return;
var id = touch.touchId.ReadValue();
var phase = touch.phase.ReadValue();
// Missing (phase == TouchPhase.Began) for some swipes
Debug.LogWarning($"Touch {id}, Phase {phase}");
}
I don’t know if this might help in your case, but I believe that is not recommended to use the Touchscreen API in an Update for pooling, Unity recommends using the EnanchedTouch for that use case: https://discussions.unity.com/t/785883
For what it’s worth, I stopped having the TouchBegan issue after updating to preview5!
For me the bug seems to still be happening for Version 1.1.1 (- September 09, 2021) and Unity 2021.1.21f1.3059 Personal. (Just trying to make a simple multitouch tester as a start)
Same code for touchphase detection like in the thread start. Touchphase.Began most times but not always run in the Update() loop, but touchcount correctly detected.
Running my test on redmi k20 miui 12.5.1 android 11.
Most times Touchphase.Began seems to have not fired when finger quickly in succession are touching.
Maybe too fast for Update() polling? Could the touchphase of late finger at end of one Update() loop get overwritten by the start of the next Update() loop without firing?
Note: You should not use Touchscreen for polling. If you want to read out touches similar to UnityEngine.Input.touches, see EnhancedTouch. If you read out touch state from Touchscreen directly inside of the Update or FixedUpdate methods, your app will miss changes in touch state
{
EnhancedTouchSupport.Enable();
Touch.onFingerDown += Touch_onFingerDown;
Touch.onFingerUp += Touch_onFingerUp;
Touch.onFingerMove += Touch_onFingerMove;
}
protected void OnDisable()
{
EnhancedTouchSupport.Disable();
Touch.onFingerDown -= Touch_onFingerDown;
Touch.onFingerUp -= Touch_onFingerUp;
Touch.onFingerMove -= Touch_onFingerMove;
}
private void Touch_onFingerDown(Finger latestFinger)
{
//use only the currently changed latestFinger
//or if you still need to process all fingers can still use the same function as in Update()
foreach (Finger finger in Touch.activeFingers)
{
}
}
//same for the other two functions Touch_onFingerUp(), Touch_onFingerMove()
hi, i found a hackie way around this using a bool and a timer to reset, check out below.
in - else if (Input.touchCount <= 0 && hasShotSingle) i reset the touch object to default values, this resets the touch values manually, so far no issues.