Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Reset AR Session

Discussion in 'Handheld AR' started by blanx, Jun 22, 2018.

  1. blanx

    blanx

    Joined:
    Feb 26, 2016
    Posts:
    42
    Is there a way to reset the AR session?

    I tried to use this in, but it seems it does not do anything:
    ARSubsystemManager.DestroySubsystems();
    ARSubsystemManager.CreateSubsystems();

    Sometimes the tracking goes wrong or when reopening an app all es messed up and I want to give the users to reset the scene. Then all planes have to removed and the tracking points and so on.
    For ARKit I had a script that can do this, but now with foundation it seems a bit more difficult.
     
  2. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    792
    You should be able to destroy the ARSession GameObject and Instantiate a new one to achieve this.
     
  3. blanx

    blanx

    Joined:
    Feb 26, 2016
    Posts:
    42
    Thanks. Will try that.
    And then it is just a matter of destroying the visual planes to have a clean new session?
     
  4. TijsVdV

    TijsVdV

    Joined:
    Mar 7, 2017
    Posts:
    11
    Did this work for you? I tried this but when but i get this error when enabeling the newly spawned arsession: InvalidOperationException: Cannot start AR session because there is no session subsystem
     
  5. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    227
    Same here, "InvalidOperationException: Cannot start AR session because there is no session subsystem." when enabling ARSession. I also get it if I load from SampleScene to another scene and then try to load SampleScene again.

    Update: Exception only occurs in the Editor.
     
    Last edited: Jun 27, 2018
  6. StefanAugmentors

    StefanAugmentors

    Joined:
    Nov 3, 2017
    Posts:
    15
    Hi. Did destroying the AR Session object and re-instantiating work for anyone? I get a black screen when I do that.
     
  7. WolfBeardedLion

    WolfBeardedLion

    Joined:
    Apr 5, 2013
    Posts:
    27
    I'm also getting a black screen, instead of the camera feed, after destroying the ARSession component and then adding it back to the same gameObject.
     
  8. StefanAugmentors

    StefanAugmentors

    Joined:
    Nov 3, 2017
    Posts:
    15
    I couldn't find a nice way to reset the session. For now I get all the planes and point clouds and destroy/disable them manually.
     
  9. Phoera

    Phoera

    Joined:
    Mar 10, 2015
    Posts:
    9
    If I'm reloading AR scene for the second time, I'm getting the "Cannot start AR session.." error, and device is not tracking any planes, due to session fail
     
  10. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    490
    I just did a test on a Pixel where I enabled/disabled the ARSession component, and also Destroyed and Instantiated it. All seemed to work as expected.

    For this particular issue:
    What device and OS version?
     
  11. Cowcak

    Cowcak

    Joined:
    Mar 11, 2015
    Posts:
    7
    I have the same issue when loading scene again. Just one note that I'm using multiple scenes loaded additively and AR session lives in the scene from scene load.
     
  12. Phoera

    Phoera

    Joined:
    Mar 10, 2015
    Posts:
    9
    I can't already reproduce this exact error, it's been lost in the iterations of fixing attempts.
    The thing is I was trying to fix nonexistent error, because it was only in the Editor, as soon as I built my app for device, everything went okay.
    I used directives for ARSubsystemManager functions, because all of the systems are null in the editor, therefore it can't function properly.

    So it looks like this and works like charm even when reloading scene:

    Code (CSharp):
    1. void Start()
    2.     {
    3. #if !UNITY_EDITOR
    4.         ARSubsystemManager.DestroySubsystems();
    5.         ARSubsystemManager.CreateSubsystems();
    6.         ARSubsystemManager.StopSubsystems();
    7.         arSession.gameObject.SetActive(false);
    8. #endif
    9.     }
    10.  
    11. public async void StartTracking()
    12.     {
    13. #if !UNITY_EDITOR
    14.         arSession.gameObject.SetActive(true);
    15.         ARSubsystemManager.StartSubsystems();
    16.         arPlaneManager.planeAdded += PlaneTracked;
    17. #else
    18.         //here comes some emulation of plane tracking for Editor:
    19.         //PlaceInfinitePlane(Vector3.zero);
    20.         //await new WaitForSeconds(1f);
    21.         //OnPlaneTracked?.Invoke();
    22. #endif
    23.     }
    24.  
    May it help someone to figure out how to handle reload of ar session =)
     
    Last edited: Jul 12, 2018
    WolfBeardedLion likes this.
  13. StefanAugmentors

    StefanAugmentors

    Joined:
    Nov 3, 2017
    Posts:
    15
    Same here. I think multiple scenes is breaking something.
     
  14. headlessstudio

    headlessstudio

    Joined:
    Feb 25, 2016
    Posts:
    57
    We're also having the same issue with reloading the scene a second time and getting a black screen. Samsung S8 and Android, and iPhone 7 Plus and iOS 12
     
  15. FlorentPoittevin

    FlorentPoittevin

    Joined:
    Jun 29, 2019
    Posts:
    2
    Same problem here
     
  16. FlorentPoittevin

    FlorentPoittevin

    Joined:
    Jun 29, 2019
    Posts:
    2