Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Bug 2021.2 EnhancedTouch stopped working on device

Discussion in '2021.2 Beta' started by IljaDaderko, Oct 12, 2021.

  1. IljaDaderko

    IljaDaderko

    Joined:
    Oct 25, 2019
    Posts:
    7
    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.


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.InputSystem.EnhancedTouch;
    4. using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;
    5.  
    6.  
    7. public class GameUiManager : MonoBehaviour
    8. {
    9.  
    10.  
    11.     // Fields
    12.     [SerializeField] private GameObject movementStrip;
    13.     private Rect movementStripRect;
    14.     private float movementMaxValue;
    15.     private float movementMinValue;
    16.  
    17.  
    18.     // Lifecycle Methods
    19.     private void Start()
    20.     {
    21.         CreateMovementStripRect();
    22.     }
    23.  
    24.  
    25.     private void OnEnable()
    26.     {
    27.         EnhancedTouchSupport.Enable();
    28.     }
    29.  
    30.  
    31.     private void OnDisable()
    32.     {
    33.         EnhancedTouchSupport.Disable();
    34.     }
    35.  
    36.  
    37.     private void Update()
    38.     {
    39.         HandleMovementStripInteraction();
    40.     }
    41.  
    42.  
    43.     private void HandleMovementStripInteraction()
    44.     {
    45.         if (Touch.activeFingers.Count >= 1)
    46.         {
    47.             bool isActiveFinger = false;
    48.             float movePosition = 0;
    49.  
    50.             foreach (Finger finger in Touch.activeFingers)
    51.             {
    52.                 Vector2 fingerPosition = finger.screenPosition;
    53.                 if (movementStripRect.Contains(fingerPosition))
    54.                 {
    55.                     isActiveFinger = true;
    56.                     movePosition = fingerPosition.x;
    57.                     break;
    58.                 }
    59.             }
    60.  
    61.             if (isActiveFinger)
    62.             {
    63.                 HandlePlayerMovementEvents(movePosition);
    64.             }
    65.         }
    66.     }
    67.  
    68.  
    69.     private void HandlePlayerMovementEvents(float movePosition)
    70.     {
    71.         float normalizedPosition = Mathf.InverseLerp(movementMinValue, movementMaxValue, movePosition);
    72.  
    73.         if (normalizedPosition <= 0.25 )
    74.         {
    75.             GameManager.Instance.SetPlayerPosition(PlayerPosition.Left);
    76.         } else if (normalizedPosition <= 0.75 )
    77.         {
    78.             GameManager.Instance.SetPlayerPosition(PlayerPosition.Middle);
    79.         } else if (normalizedPosition <= 1 )
    80.         {
    81.             GameManager.Instance.SetPlayerPosition(PlayerPosition.Right);
    82.         }
    83.     }
    84.  
    85.  
    86.     private void CreateMovementStripRect()
    87.     {
    88.         float scaleFactor = Screen.width / GetComponent<CanvasScaler>().referenceResolution.x;
    89.         Transform stripTransform = movementStrip.transform;
    90.         RectTransform stripRect = (RectTransform)stripTransform;
    91.         movementStripRect = new Rect(
    92.             stripTransform.position.x,
    93.             stripTransform.position.y,
    94.             stripRect.sizeDelta.x * scaleFactor,
    95.             stripRect.sizeDelta.y * scaleFactor
    96.         );
    97.         movementMaxValue = stripTransform.position.x + stripRect.sizeDelta.x * scaleFactor;
    98.         movementMinValue = stripTransform.position.x;
    99.     }
    100.  
    101.  
    102. }
    103.  
     
  2. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    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.
     
  3. IljaDaderko

    IljaDaderko

    Joined:
    Oct 25, 2019
    Posts:
    7
    Submitted
     
    LeonhardP likes this.
  4. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    Thank you, could you please share the issue ID here?
     
  5. IljaDaderko

    IljaDaderko

    Joined:
    Oct 25, 2019
    Posts:
    7
    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
     
    Last edited by a moderator: Nov 8, 2021
    LeonhardP likes this.