Search Unity

Bug Touch actions are reversed after build on Google Pixel 3

Discussion in 'AR' started by MdevM, Feb 19, 2023.

  1. MdevM

    MdevM

    Joined:
    Sep 28, 2017
    Posts:
    43
    Hi everyone,

    I have an issue after I build my app which uses AR Core onto my Google pixel 3.

    When I use my finger to do actions such as swiping and smudging, it seems like everything moves in the opposite direction to which my finger moves, this is very strange because when I run the game in the Editor, everything works correctly.

    Imagine something like Fruit Ninja, the swiping works in the Editor but as soon as I build onto my Google Pixel 3, the swipes go in the opposite direction to my finger.

    ARCore XR Plugin version : 3.1.10
    AR Foundation version : 3.1.3

    Has anyone ever experienced something like this before? I can't pinpoint the issue since everything works in the scene correctly...

    Any help would be greatly appreciated!
     
  2. MdevM

    MdevM

    Joined:
    Sep 28, 2017
    Posts:
    43
    Wanted to add that I’m using the user facing camera.
     
  3. MdevM

    MdevM

    Joined:
    Sep 28, 2017
    Posts:
    43
    I found that my touch input is actually where it should be, it's my trail renderer which is going in the opposite direction, plus, it renders strangely, broken up.

    I have problems with out position based graphics too, I wonder what the android build pipeline is doing to these systems..

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using DarkTonic.MasterAudio;
    4. using UnityEngine;
    5.  
    6. public class Blade : MonoBehaviour
    7. {
    8.     private bool isCutting = false;
    9.  
    10.     Rigidbody rb;
    11.  
    12.     public Camera cam;
    13.  
    14.     public GameObject bladeTrailPrefab;
    15.  
    16.     public GameObject currentBladeTrail;
    17.  
    18.     public PlaySoundResult bladeBrushSound;
    19.  
    20.     public float lastXPos;
    21.  
    22.     public float lastYPos;
    23.  
    24.     public bool hasStoppedMovingFast;
    25.  
    26.     private void Start()
    27.     {
    28.         rb = GetComponent<Rigidbody>();
    29.         lastXPos = rb.position.x;
    30.         lastYPos = rb.position.y;
    31.     }
    32.  
    33.     void Update()
    34.     {
    35.          UpdateCut();
    36.         if (Input.GetMouseButtonDown(0))
    37.         {
    38.             //StartCutting();
    39.             StartCoroutine(StartCutting());
    40.         }
    41.         else if (Input.GetMouseButtonUp(0))
    42.         {
    43.             StartCoroutine(StopCutting());
    44.         }
    45.  
    46.      
    47.     }
    48.  
    49.     void UpdateCut()
    50.     {
    51.         rb.position =
    52.             cam
    53.                 .ScreenToWorldPoint(new Vector3(Input.mousePosition.x,
    54.                     Input.mousePosition.y,
    55.                     -cam.transform.position.z));
    56.  
    57.         if (Input.GetMouseButton(0))
    58.         {
    59.             if (
    60.                 (
    61.                 Mathf.Abs(lastXPos - rb.position.x) +
    62.                 Mathf.Abs(lastYPos - rb.position.y)
    63.                 ) >
    64.                 1
    65.             )
    66.             {
    67.                 if (hasStoppedMovingFast)
    68.                 {
    69.                     hasStoppedMovingFast = false;
    70.                     bladeBrushSound =
    71.                         MasterAudio.PlaySound("Brush_1", 100, 1, 0f);
    72.                 }
    73.             }
    74.             else
    75.             {
    76.                 hasStoppedMovingFast = true;
    77.             }
    78.         }
    79.  
    80.         lastXPos = rb.position.x;
    81.         lastYPos = rb.position.y;
    82.     }
    83.  
    84.     // void StartCutting()
    85.     // {
    86.     //     UpdateCut();
    87.     //     hasStoppedMovingFast = true;
    88.  
    89.     //     //bladeBrushSound = MasterAudio.PlaySound("Brush_1", 100, 1, 0f);
    90.     //     isCutting = true;
    91.     //     currentBladeTrail.GetComponent<TrailRenderer>().Clear();
    92.     //     currentBladeTrail = Instantiate(bladeTrailPrefab, transform);
    93.     //     currentBladeTrail.GetComponent<TrailRenderer>().Clear();
    94.     // }
    95.  
    96.     private IEnumerator StartCutting()
    97.     {
    98.         UpdateCut();
    99.         //currentBladeTrail.GetComponent<TrailRenderer>().Clear();
    100.         yield return new WaitForSeconds(0.05f);
    101.         hasStoppedMovingFast = true;
    102.         currentBladeTrail = Instantiate(bladeTrailPrefab, transform);
    103.     }
    104.  
    105.     private IEnumerator StopCutting()
    106.     {
    107.         if (bladeBrushSound != null)
    108.         {
    109.             if (bladeBrushSound.ActingVariation != null)
    110.             {
    111.                 bladeBrushSound.ActingVariation.Stop();
    112.             }
    113.         }
    114.         isCutting = false;
    115.         yield return new WaitForSeconds(0.05f);
    116.         currentBladeTrail.transform.SetParent(null);
    117.         //currentBladeTrail.GetComponent<TrailRenderer>().Clear();
    118.         Destroy(currentBladeTrail, 2f);
    119.     }
    120. }
    121.  


    Here is the code for my trail renderer system which becomes inverted on my android build.
     
  4. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    Hi @MdevM

    Note that this question is not AR-specific and might be better suited for another forum. The presence of AR Foundation in your build does not affect touch input. I would recommend building up from a simpler demo to understand how touch input is handled on mobile devices. This code is challenging to debug given all the coroutines and state mutation involved, so starting from a simple demo might help.

    Note also that AR Foundation 3 has reached end of life and is no longer supported. We strongly encourage you to upgrade to AR Foundation 4.2.
     
  5. MdevM

    MdevM

    Joined:
    Sep 28, 2017
    Posts:
    43

    Thanks for your reply, I initially thought ARCore was doing something funny because everything worked smoothely on IOS where as I had a lot of strange things happening related to face tracking but after further debugging I found that most issues were not related to each other.

    There must be something going on during the android compilation process or something specific to android devices which makes this code / trail renderer behave differently compared to the scene editor and IOS builds.

    I would update to 4.2 if my project didn't completely break with new unity versions, I have to use 2019.17.1f, I've tried updating and my project just breaks in too many ways, I'd rather keep all my versions as is atleast for now.
     
    andyb-unity likes this.
  6. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    Unity 2019 has also reached end of life and is no longer supported, although I know there is a subset of the community that still uses it. Good luck!
     
  7. MdevM

    MdevM

    Joined:
    Sep 28, 2017
    Posts:
    43
    After more testing, I still thinking it has something to do with AR Core and the selfie / front/user facing camera.
    Here are some videos of the issue.
    This is how it should work and how it works in the Editor and on IOS devices

    This is how it works on Android devices
    https://www.youtube.com/shorts/fK7zTbtsRgY

    What could be causing this behaviour?
     
    Last edited: Mar 9, 2023
  8. MdevM

    MdevM

    Joined:
    Sep 28, 2017
    Posts:
    43
    So it turns out this was definitely an AR related question.

    ARCore + User facing Camera = Trail Renderers render in the opposite direction, away from the camera, which causes this issue.