Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question AR Foundation losing tracking, objects stick to screen until regain track.

Discussion in 'AR' started by mdYeet, May 20, 2021.

  1. mdYeet

    mdYeet

    Joined:
    Oct 21, 2020
    Posts:
    22
    Hello all,

    I was wondering if someone could point me in the right direction here. I'm looking for some type of event data or callback that happens when tracking is lost due to low contrast/feature points in the environment. This causes all objects in the scene/viewed through the camera to stick to the screen. It "un-sticks" once tracking is regained by either looking at the ground for example, or looking at something with more feature points for the system to track.

    Thanks in advance!!
     
  2. mdYeet

    mdYeet

    Joined:
    Oct 21, 2020
    Posts:
    22
    The reason I would like this is to pause the game and inform the user of the occurrence, so that they may fix themselves to a better area or able to quit/restart the game.
     
  3. mdYeet

    mdYeet

    Joined:
    Oct 21, 2020
    Posts:
    22
    I will post a video of this today, but bump
     
  4. mdYeet

    mdYeet

    Joined:
    Oct 21, 2020
    Posts:
    22



    This happens way more/almost only on Android ARCore than it does on iOS ARKit.
     
  5. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,816
    JanetGilbertPraxis likes this.
  6. unknownsk

    unknownsk

    Joined:
    Jan 16, 2020
    Posts:
    36
    This is very annoying problem. I still can not solve it. Why can not objects just stay where they are when tracking is lost instead of following the camera?
     
  7. todds_unity

    todds_unity

    Joined:
    Aug 1, 2018
    Posts:
    324
    The camera position and orientation is driven by AR. When tracking is lost, the camera transform remains at the last tracked position and orientation.

    The camera background may still be updating while tracking is lost.

    This is the expected behavior from the device.

    You can listen to the ARSession.stateChanged event and alter your apps behavior when tracking is lost.
     
  8. cocchialorenzo

    cocchialorenzo

    Joined:
    Dec 11, 2021
    Posts:
    1
    Attaching a callback to ARSession.stateChanged event you can realize if the state goes from SessionTracking (ok) to SessionInitializing (lost tracking in this case). From here, you should be able to calibrate again your environment or at least to notify the user.
     
  9. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    884
    For the weary folks that have come here from Google. Here's how to do it:

    Code (CSharp):
    1.     void onChange(ARSessionStateChangedEventArgs eventArgs)
    2.     {
    3.         if (eventArgs.state==ARSessionState.SessionInitializing)
    4.         {
    5.             // do something wonderful
    6.         }
    7.     }
    8.  
    9.  
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.         ARSession.stateChanged+= onChange;
    14.     }
    15.  
     
    AldeRoberge and andyb-unity like this.