Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Checking for AR availability BEFORE launching AR scene?

Discussion in 'Handheld AR' started by Saicopate, Nov 5, 2018.

  1. Saicopate

    Saicopate

    Joined:
    Sep 25, 2017
    Posts:
    54
    I am trying to build some logic to test the device after app start to decide whether to allow for AR scene or only conventional 3D scene.
    I know we can use
    ARSubsystemManager.systemState
    to check that but this works only when AR Session component is present in the scene, which means that there needs to be an attempt to initialize AR Session.
    This is pretty expensive task that I would like to avoid straight after launching the app.

    Is there any way around?
     
  2. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    467
    Checkout ARSubsystemManager.checkAvailability(). It is meant to be run as a coroutine (see ARSession.Initialize for an example).

    On Android, the availability check can take several frames because if ARCore is not installed already (or the app the requires a newer version of ARCore), then it has to check with the Play Store to see if there is a version of ARCore which supports that particular device.

    Note that when deploying an ARCore required app from Unity (e.g., click "Build and Run"), unsupported devices will be reported as supported because the Play Store would not have allowed the app to be installed on an unsupported device in the first place.
     
  3. Saicopate

    Saicopate

    Joined:
    Sep 25, 2017
    Posts:
    54
    Thanks Tim, I tried ARSubsystemManager.checkAvailability() in a coroutine but is doesn't work unless AR Session is initilized - systemState is returning "Unsupported". When checking systemState in AR-enabled scene it works ok.

    I guess it is due to these lines of code inside ARSubsystemManager.checkAvailability():

    Code (CSharp):
    1.             if (sessionSubsystem == null)
    2.             {
    3.                 systemState = ARSystemState.Unsupported;
    4.             }
    For me this means you need to try to initialize AR Session first to check whether it will work.
    Of course I am considering this for an "AR-optional" app, where depending on the device compatibility the user is given either 3D-only or 3D+AR options.
     
  4. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    467
    You'll need to call ARSubsystemManager.CreateSubsystems() before you check availability (basically copy what ARSession.OnEnable does).
     
  5. Saicopate

    Saicopate

    Joined:
    Sep 25, 2017
    Posts:
    54
    Ended up doing like you said, thanks!
     
  6. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    386
    Hi @Saicopate, would you be willing to share what you did to establish AR availability? Thx!
     
    newguy123 likes this.
  7. Saicopate

    Saicopate

    Joined:
    Sep 25, 2017
    Posts:
    54
    Sure.
    I run this at the start of non-AR scene (replace Debug.Log with your own implementation).

    Code (CSharp):
    1.    
    2. private void OnEnable()
    3.     {
    4.         ARSubsystemManager.CreateSubsystems();
    5.         StartCoroutine(ARSubsystemManager.CheckAvailability());
    6.         StartCoroutine(AllowARScene());
    7.     }
    8.  
    9. IEnumerator AllowARScene()
    10.     {
    11.         while (true)
    12.         {
    13.             while (ARSubsystemManager.systemState == ARSystemState.CheckingAvailability ||
    14.                 ARSubsystemManager.systemState == ARSystemState.None)
    15.             {
    16.                 Debug.Log("Waiting...");
    17.                 yield return null;
    18.             }
    19.             if (ARSubsystemManager.systemState == ARSystemState.Unsupported)
    20.             {
    21.                 Debug.Log("AR unsupported");
    22.                 yield break;
    23.             }
    24.             if (ARSubsystemManager.systemState > ARSystemState.CheckingAvailability)
    25.             {
    26.                 Debug.Log("AR supported");
    27.                 yield break;
    28.             }
    29.         }      
    30.     }
    31.  
     
    sameel and christougher like this.
  8. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
    Hi
    Implemented the solution above.. appears to be working thanks @Saicopate && @tdmowrer

    One question.. if using this check in non AR main menu... should I use

    Code (CSharp):
    1. ARSubsystemManager.DestroySubsystems()
    .. after I have completed the check and before I load into my AR scene? as per ARSession?

    Or will these subsystems get destroyed gracefully when I unload the main menu scene and load the new AR scene?

    Thanks
     
  9. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    467
    You shouldn't need to destroy it in your case since you are about to start an AR scene. It is safe to call
    ARSubsystemManager.CreateSubsystems()
    multiple times (the second time is effectively a no-op).

    If you did not immediately start your AR scene, then you might want to call
    DestroySubsystems
    just to make sure you cleanly shut down the AR session.
     
    GreeneMachine likes this.
  10. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
    hey @tdmowrer

    I have my ARCore Optional app working on devices that do not support arcore etc. And use the above logic to enable AR within my game.

    How would I do same for IOS? Such that my app will be made available to all devices running target IOS ver 11... whether they support ARKit or not.. and then allow the logic above to control enabling/disabling AR within my game.

    Thanks
     
  11. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    467
    There is a similar setting for ARKit, see the "ARKit Required" section of https://docs.unity3d.com/Packages/c...ual/index.html#creating-a-arkitsettings-asset
     
  12. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
  13. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    467
    I believe it was added in a later version. 2018.2 is no longer supported, so you'd need to upgrade to 2018.3 to be able to use this feature. Alternatively, you can manually set it in Xcode; see https://developer.apple.com/documen...ice_support_and_user_permission?language=objc
     
    GreeneMachine likes this.
  14. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    386
    How can we update this to work in Unity 2019? ARSubsystemManager and ARSystemState no longer seems to exist.
     
  15. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    467