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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question AR foundation: when phone camera is covered, instantiated object is glued to the camera

Discussion in 'AR' started by pouria77, Feb 23, 2022.

  1. pouria77

    pouria77

    Joined:
    Aug 13, 2014
    Posts:
    36
    I downloaded the AR Foundation samples from Unity, and made a build of one of the scenes called ImageTrackingWithMultiplePrefabs and put it on my android phone.

    The build works fine when scanning markers, but as soon as the camera is covered, the object is glued to the camera, and I have to either look at the marker again, or restart the app to fix it.
    This is going to be an issue because we're making an app and it could happen a lot, for example when the user puts their phone down.

    I made a video to better explain the issue:


    More info:
    Unity version: 2020.3.20f1
    AR Foundation version: 4.1.9
    phone: google pixel 5 (but it also happened on my Samsung galaxy S10)

    I put a log in the PrefabPairImageManager.cs script and noticed that when we look away, the tracking changes to limited, and stays the same, even when the camera is covered. So there's no way for me to find out when the camera is covered in code based on the tracking info.

    What am I doing wrong?
    Thanks a lot
     
    Last edited: Feb 24, 2022
  2. todds_unity

    todds_unity

    Unity Technologies

    Joined:
    Aug 1, 2018
    Posts:
    324
    You should hide your object when the image tracking state for the ARTrackedImage.trackingState and hide your game object when the tracking state is not TrackingState.Tracking.
    https://docs.unity3d.com/Packages/c...e_XR_ARFoundation_ARTrackable_2_trackingState

    In your video, the issue is also occurring with the cube. However, in the case of the cube, the center of the cube is attached to the eye, and thus, you are looking at the backfaces of the cube which do not get rendered.
     
  3. pouria77

    pouria77

    Joined:
    Aug 13, 2014
    Posts:
    36
    hey thanks for the response, but I don't want to hide it.. I want it to stay there so users can go far and still see them. This was possible in previous versions, not to destroy the object when tracking is gone, so I wanna do the same here.
     
  4. todds_unity

    todds_unity

    Unity Technologies

    Joined:
    Aug 1, 2018
    Posts:
    324
    The behavior comes from the platform SDK, Google ARCore in your case.
     
    pouria77 likes this.