Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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:
    36
    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:
    272
    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:
    36
    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:
    272
    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:
    36
    Ended up doing like you said, thanks!
     
  6. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    336
    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:
    36
    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.  
     
    christougher likes this.