2021.2 EnhancedTouch stopped working on device

After updating from 2021.1 to 2021.2 using version from website (not hub) code below, in particular Enhanced touch bits have stopped working when app is built to device, It still works in game window when running in unity.

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.InputSystem.EnhancedTouch;
using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;


public class GameUiManager : MonoBehaviour
{


    // Fields
    [SerializeField] private GameObject movementStrip;
    private Rect movementStripRect;
    private float movementMaxValue;
    private float movementMinValue;


    // Lifecycle Methods
    private void Start()
    {
        CreateMovementStripRect();
    }


    private void OnEnable()
    {
        EnhancedTouchSupport.Enable();
    }


    private void OnDisable()
    {
        EnhancedTouchSupport.Disable();
    }


    private void Update()
    {
        HandleMovementStripInteraction();
    }


    private void HandleMovementStripInteraction()
    {
        if (Touch.activeFingers.Count >= 1)
        {
            bool isActiveFinger = false;
            float movePosition = 0;

            foreach (Finger finger in Touch.activeFingers)
            {
                Vector2 fingerPosition = finger.screenPosition;
                if (movementStripRect.Contains(fingerPosition))
                {
                    isActiveFinger = true;
                    movePosition = fingerPosition.x;
                    break;
                }
            }

            if (isActiveFinger)
            {
                HandlePlayerMovementEvents(movePosition);
            }
        }
    }


    private void HandlePlayerMovementEvents(float movePosition)
    {
        float normalizedPosition = Mathf.InverseLerp(movementMinValue, movementMaxValue, movePosition);

        if (normalizedPosition <= 0.25 )
        {
            GameManager.Instance.SetPlayerPosition(PlayerPosition.Left);
        } else if (normalizedPosition <= 0.75 )
        {
            GameManager.Instance.SetPlayerPosition(PlayerPosition.Middle);
        } else if (normalizedPosition <= 1 )
        {
            GameManager.Instance.SetPlayerPosition(PlayerPosition.Right);
        }
    }


    private void CreateMovementStripRect()
    {
        float scaleFactor = Screen.width / GetComponent<CanvasScaler>().referenceResolution.x;
        Transform stripTransform = movementStrip.transform;
        RectTransform stripRect = (RectTransform)stripTransform;
        movementStripRect = new Rect(
            stripTransform.position.x,
            stripTransform.position.y,
            stripRect.sizeDelta.x * scaleFactor,
            stripRect.sizeDelta.y * scaleFactor
        );
        movementMaxValue = stripTransform.position.x + stripRect.sizeDelta.x * scaleFactor;
        movementMinValue = stripTransform.position.x;
    }


}

Hi @IljaDaderko ,

Could you please submit a bug report for this issue with reproduction steps attached and a description of the expected versus actual results? Also, please include information about which device(s) you have tried this on.

Submitted

1 Like

Thank you, could you please share the issue ID here?

Sure thing, issue is here
https://fogbugz.unity3d.com/default.asp?1378315

I believe issue id is: 1378315

There are now few additional details I can add

  1. Issue occurs on iPhone XS and iPhone 13 Pro (iOS 15)
  2. It still remains in latest version (now downloaded from the hub) 2021.2.1
  3. Occurs on both “Intel” and “Silicon” versions
  4. Other input system touch events that use Player Input and things like On-Screen Button, do work

I’ll keep looking into this, but its hard to debug as it does work in editor and there are no errors

1 Like