Search Unity

ARSession.Reset() doesn't remove all trackables immediately

Discussion in 'AR' started by pacolaf, Jul 19, 2019.

  1. pacolaf

    pacolaf

    Joined:
    Feb 2, 2014
    Posts:
    5
    I have a button in my app to reset the floor detection. I use ARSession.Reset() to reset the session, then the app shows a message for the user to move the device around to detect the floor, and I check if ARPlaneManager.trackables.count > 0 to know if some surface has been detected and in that case hide the message. The problem is that during some frames after resetting the ARSession, ARPlaneManager.trackables.count is still greater than zero, and I have to wait some frames to get a value of zero. It seems that there is some delay between the ARSession reset and the end of the trackables removing process, probably because it is done asynchronously.

    Is this the correct behavior of ARSession.Reset() or is it a bug? I made a workaround but I would like to know if there is a better way to check if a new surface is detected after an ARSession reset. I'm using AR Foundation 2.2, and with version 1.x it worked well with no delay.
     
  2. pacolaf

    pacolaf

    Joined:
    Feb 2, 2014
    Posts:
    5
    I think I found the right way to do that. I have to check ARSession.state before checking the ARPlaneManager trackables count. I only can trust the trackables count value after the ARSession has finished its initialization after a reset. After the ARSession reset, its state is ARSessionState.SessionInitializing for some frames and in that state maybe not every previous trackable has been removed yet.

    Code (CSharp):
    1. if (ARSession.state == ARSessionState.SessionTracking)
    2. {
    3.     if (m_ARPlaneManager.trackables.count > 0)
    4.     {
    5.         surfaceDetected = true;
    6.     }
    7. }
     
    Last edited: Jul 19, 2019
    KibsgaardUnityStudios likes this.