Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Block canvas UI Button touches from reaching loaded AR scene.

Discussion in 'AR' started by jwanga, Jan 11, 2021.

  1. jwanga

    jwanga

    Joined:
    Dec 17, 2018
    Posts:
    7
    I'm building an iOS app in which I load an AR scene built with Vuforia at runtime. After the scene is loaded, I instantiate a canvas prefab I created in the new scene with some UI buttons. The issue is that when you touch a button the touch is passed through to the underlying scene and anchors the AR object to the plane. How do I prevent this behavior using a loaded scene I don't control?
     
  2. Alexis-Dev

    Alexis-Dev

    Joined:
    Apr 16, 2019
    Posts:
    121
    Hello,

    I recommend you to create a script to check if you touch a UI element or not.

    Like doing a ARRaycast or PhysicalRaycast if :
    Code (CSharp):
    1. public static bool IsPointerOverUIObject(Vector2 touchPosition)
    2.         {
    3.             PointerEventData pointerEventData = new PointerEventData(EventSystem.current);
    4.             pointerEventData.position = touchPosition;
    5.             List<RaycastResult> raycastResults = new List<RaycastResult>();
    6.  
    7.             EventSystem.current.RaycastAll(pointerEventData, raycastResults);
    8.  
    9.             return raycastResults.Count > 0;
    10.         }
    return false.
     
  3. jwanga

    jwanga

    Joined:
    Dec 17, 2018
    Posts:
    7
    Problem is that I don't control the loaded scene. only parent scene that the scene is loaded into
     
  4. Alexis-Dev

    Alexis-Dev

    Joined:
    Apr 16, 2019
    Posts:
    121
    Humm... In this way, I don't know...
     
  5. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,796
  6. jwanga

    jwanga

    Joined:
    Dec 17, 2018
    Posts:
    7
    For posterity. I eventually sorted out that Vuforia natively ignores UI clicks just fine. However, because I was loading a bundled Vuforia scene into my main scene, I needed to include a Vuforia ARCamera in my main scene. I have no idea why, but it worked.