Search Unity

Why !EventSystem.current.IsPointerOverGameObject(touch.fingerId) is not working anymore?

Discussion in 'AR' started by zyonneo, Jan 15, 2019.

Thread Status:
Not open for further replies.
  1. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    386
    The below code used to work for me when I tested it few months back.Now I cant see it working.The hit gets registered behind the UI always and the model that I placed using the UNITYARHIT example scene gets placed behind the UI.

    Code (CSharp):
    1. #else
    2.         if (Input.touchCount > 0 && m_HitTransform != null)
    3.         {
    4.             var touch = Input.GetTouch(0);
    5.             if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved && !EventSystem.current.IsPointerOverGameObject(touch.fingerId))
    6.             {
    7.                 var screenPosition = Camera.main.ScreenToViewportPoint(touch.position);
    8.                 ARPoint point = new ARPoint {
    9.                     x = screenPosition.x,
    10.                     y = screenPosition.y
    11.                 };
    12.  
    13.                 // prioritize reults types
    14.                 ARHitTestResultType[] resultTypes = {
    15.                     ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingGeometry,
    16.                     //ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent,
    17.                     // if you want to use infinite planes use this:
    18.                    // ARHitTestResultType.ARHitTestResultTypeExistingPlane,
    19.                     ARHitTestResultType.ARHitTestResultTypeEstimatedHorizontalPlane,
    20.                     //ARHitTestResultType.ARHitTestResultTypeEstimatedVerticalPlane,
    21.                     //ARHitTestResultType.ARHitTestResultTypeFeaturePoint
    22.                 };
    23.  
    24.                 foreach (ARHitTestResultType resultType in resultTypes)
    25.                 {
    26.                     if (HitTestWithResultType (point, resultType))
    27.                     {
    28.                         return;
    29.                     }
    30.                 }
    31.             }
    32.         }
    33.         #endif
    The below script I have added to the model to swipe to rotate.On touch the model moves awkwardly.It moves along the plane and rotates.Once the plane gets detected do I have to turn off the plane detection to make the rotation with swipe working?

    Code (CSharp):
    1. if(Input.touchCount==2  &&  Input.GetTouch(0).phase==TouchPhase.Moved)
    2.     {
    3.         // Get movement of the finger since last frame
    4.         Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
    5.  
    6.  
    7.         transform.Rotate(Vector3.up ,touchDeltaPosition.x * rotspeed * Time.deltaTime, Space.World);
    8.        // transform.Rotate(Vector3.right,touchDeltaPosition.y * rotspeed * Time.deltaTime,Space.World);
    9.  
    10.  
    11.     }
     
  2. Hassan-Kanso

    Hassan-Kanso

    Joined:
    Jun 10, 2014
    Posts:
    11
    Hello I've the same problem, I hope to find a solution somewhere
     
  3. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    386
    Code (CSharp):
    1. if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved  )
    2.                 {
    3.                     if(!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
    4.                     {
    5.                     //do stuff
    6.                      }
    7. }
    Hassan-Kanso...I think the problem is with the format we r applying..try this format..Its working for me or try wrapping touch.phase inside brackets like this ((touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved ) ).....
    Code (CSharp):
    1. if ((touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved ) && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
    2. {
    3.  
    4. }
     
    Last edited: Jan 31, 2019
    FlavioCampelo likes this.
  4. pacolaf

    pacolaf

    Joined:
    Feb 2, 2014
    Posts:
    5
    Hello,

    I'm having the same problem every time I update Unity, more specifically after the last three updates. I'm using IsPointerOverGameObject in two different scripts. In one of them it works and in the other one fails. After some researching it seems that the function doesn't work only during one frame after detecting the touch.

    I have found a solution: if I delete the obj folder inside my project folder, the next time I run my app it works perfectly, without changing a single line of code.

    I hope this will help someone until the strange bug is corrected.
     
  5. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    386
    Have you tested the above code which I tried?
     
  6. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    199
    same issue with 2019.3.0b10 and 2019.3.f0
     
    Last edited: Dec 12, 2019
  7. www_3dart_es

    www_3dart_es

    Joined:
    May 24, 2013
    Posts:
    219
    same! Unity 2019.2.17
     
    unnanego likes this.
  8. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    199
    This is how I resolved it (see the attached script).
    The solution is to limit the check to only one go, the first check works fine
     

    Attached Files:

    SwapnilRane and ina like this.
  9. ben-rasooli

    ben-rasooli

    Joined:
    May 1, 2014
    Posts:
    40
    In my case
    EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)
    returns true while the
    EventSystem.current.currentSelectedGameObject
    is null and wise versa! I found out that it's one frame behind. So I changed to
    if (!EventSystem.current.currentSelectedGameObject)
    and it's works now.
     
    mhmde3, ahmedfawaz_hutch and unnanego like this.
  10. StealthNinjaX

    StealthNinjaX

    Joined:
    Apr 3, 2020
    Posts:
    1
    For anyone still looking for a workaround, the solution that worked for me was using a Graphics Raycaster and checking if the amount of raycast results was 0. If it was not 0, the function returns and the code stops executing.

    Code (CSharp):
    1. public GraphicRaycaster raycaster;
    2. public PointerEventData pointerEventData;
    3.  
    4. // ...
    5.  
    6. void Update()
    7. {
    8.     // ...
    9.    
    10.     Touch touch = Input.GetTouch(0);
    11.     pointerEventData = new PointerEventData(EventSystem.current);
    12.     pointerEventData.position = touch.position;
    13.     List<RaycastResult> results = new List<RaycastResult>();
    14.     raycaster.Raycast(pointerEventData, results);
    15.  
    16.     if(results.Count != 0)
    17.     {
    18.         return;
    19.     }
    20.  
    21.     // ...
    22.  
    23. }
     
  11. Spip5

    Spip5

    Joined:
    Dec 1, 2017
    Posts:
    4
    Ben-Rasooli's solution worked for me, thanks ! For some reason during a double tap, second tap is not registered correctly with isPointingOverGameObject
     
    unnanego likes this.
  12. cyberIndia

    cyberIndia

    Joined:
    Aug 17, 2014
    Posts:
    8
    This is so stupid... really frustratingly stupid Unity!!!
     
    met1903 and unnanego like this.
  13. wolilio

    wolilio

    Joined:
    Aug 19, 2019
    Posts:
    29
    oooooh ,everything need a patch!:(
     
  14. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,822
    Hey all! So, the UnityARkitPlugin is now deprecated, and it's recommended folks use AR Foundation with our ARKit XR Plug-in.
     
Thread Status:
Not open for further replies.