Search Unity

[AR Foundation] How to enable/disable camera? + ARCore Crash (related)

Discussion in 'AR' started by xLeo, Apr 17, 2020.

  1. xLeo

    xLeo

    Joined:
    Sep 21, 2010
    Posts:
    194
    The question is simple: how should we enable/disable camera and AR tracking in the same game session?
    Reason to disable camera and tracking: privacy and battery issues.
    We would like to just enable it when needed.

    Our implementation used to work on both iOS and Android. Since two months ago, it crashes our Android app on the 2nd time that AR is activated (using either PlaneManager or FaceManager).

    What are we doing wrong? This is our code to enable/disable AR:

    Code (CSharp):
    1. private void SelectARKind(ARKind kind)
    2.         {
    3.             Debug.LogFormat("[ARController.SelectARKind] Kind: {0}", kind);
    4.             bool activeState = kind != ARKind.None;
    5.             if (kind != ARKind.None) _currentARKind = kind;
    6.  
    7.             _arSessionOrigin.gameObject.SetActive(activeState);
    8.             if (_session.enabled != activeState) _session.enabled = activeState;
    9.             _arRaycastManager.enabled = kind == ARKind.Plane;
    10.             if (_planeManager)
    11.             {
    12.                 _planeManager.enabled = kind == ARKind.Plane;
    13.                 if (!_planeManager.enabled)
    14.                 {
    15.                     foreach (var arPlaneMeshVisualizer in _planeMeshVisualizers)
    16.                     {
    17.                         Destroy(arPlaneMeshVisualizer.Value.gameObject);
    18.                     }
    19.  
    20.                     _planeMeshVisualizers.Clear();
    21.                 }
    22.             }
    23.  
    24.             if (_faceManager)
    25.             {
    26.                 _faceManager.enabled = kind == ARKind.Face;
    27.                 if (!_faceManager.enabled)
    28.                 {
    29.                     for (int i = 0; i < _arFaces.Count; i++)
    30.                     {
    31.                         Destroy(_arFaces[i].gameObject);
    32.                     }
    33.  
    34.                     _arFaces.Clear();
    35.                 }
    36.             }
    37.         }
     
    MarcSpraragen likes this.
  2. xLeo

    xLeo

    Joined:
    Sep 21, 2010
    Posts:
    194
    So, does anyone have any idea on how to properly disable camera tracking on AR Foundation?
     
  3. xLeo

    xLeo

    Joined:
    Sep 21, 2010
    Posts:
    194
    Ignore this issue.

    We were doing it correctly, by enabling/disabling AR Session.
    The app was crashing due to an One Signal plugin error. We updated it to the latest version and the crash stopped occurring.
     
    Luchianno likes this.
  4. chakravarthye

    chakravarthye

    Joined:
    Mar 1, 2019
    Posts:
    4
    Hi @xLeo
    I have the same exact problem where the app crashes on the 2nd toggle. I am not using the OneSignal plugin. Do you have any idea on what else can cause this?
    Any help
     
    ROBYER1 likes this.
  5. xLeo

    xLeo

    Joined:
    Sep 21, 2010
    Posts:
    194
    I would start by removing other Android native plugins and checking if the issues are fixed.
    If they aren't, report a bug and/or complement this topic.