Search Unity

ARFoundation causes black camera screen (Unity v. 2018.4)

Discussion in 'AR' started by apventures, Jun 16, 2020.

  1. apventures

    apventures

    Joined:
    Aug 6, 2018
    Posts:
    24
    I'm having an issue where I cannot get a scene with ARFoundation to render with the phone's camera. Instead I have a black screen. I've tried updating the Link.xml file (https://github.com/Unity-Technologies/arfoundation-samples/issues/66), as well as making sure that my packages are installed correctly. I also made sure that my AndroidManifest.xml file has the correct camera permissions.

    To debug, I created a DebugText gameobject that prints DebugLog statements to the screen. By marking up the AR Session script, I'm able to see that the app jumps from "Available Subsystems found" to "Subsystems stopped". I'm having difficulties figuring out what is causing it to skip to "Subsystems stopped".
    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine.SceneManagement;
    3.  
    4. namespace UnityEngine.XR.ARFoundation
    5. {
    6.     /// <summary>
    7.     /// Controls the lifecycle and configuration options for an AR session. There
    8.     /// is only one active session. If you have multiple <see cref="ARSession"/> components,
    9.     /// they all talk to the same session and will conflict with each other.
    10.     ///
    11.     /// Enabling or disabling the <see cref="ARSession"/> will start or stop the session,
    12.     /// respectively.
    13.     /// </summary>
    14.     [DisallowMultipleComponent]
    15.     [HelpURL("https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@1.0/api/UnityEngine.XR.ARFoundation.ARSession.html")]
    16.     public class ARSession : MonoBehaviour
    17.     {
    18.         [SerializeField]
    19.         [Tooltip("If enabled, the session will attempt to update a supported device if its AR software is out of date.")]
    20.         bool m_AttemptUpdate = true;
    21.  
    22.         /// <summary>
    23.         /// If the device supports AR but does not have the necessary software, some platforms
    24.         /// allow prompting the user to install or update the software. If <see cref="attemptUpdate"/>
    25.         /// is <c>true</c>, a software update will be attempted. If the appropriate software is not installed
    26.         /// or out of date, and <see cref="attemptUpdate"/> is <c>false</c>, then AR will not be available.
    27.         /// </summary>
    28.         public bool attemptUpdate
    29.         {
    30.             get { return m_AttemptUpdate; }
    31.             set { m_AttemptUpdate = value; }
    32.         }
    33.  
    34.         /// <summary>
    35.         /// Resets the AR Session. This destroys the current session, including all trackables, and
    36.         /// then establishes a new session.
    37.         /// </summary>
    38.         public void Reset()
    39.         {
    40.             if (ARSubsystemManager.systemState < ARSystemState.Ready)
    41.                 return;
    42.  
    43.             ARSubsystemManager.StopSubsystems();
    44.             ARSubsystemManager.DestroySubsystems();
    45.             ARSubsystemManager.CreateSubsystems();
    46.             ARSubsystemManager.StartSubsystems();
    47.             // Debug txt to see if New Subsystem ever gets created
    48.             Debug.Log("New Subsystem created");
    49.         }
    50.  
    51.         /// <summary>
    52.         /// Emits a warning in the console if more than one active <see cref="ARSession"/>
    53.         /// component is active. There is only a single, global AR Session; this
    54.         /// component controls that session. If two or more <see cref="ARSession"/>s are
    55.         /// simultaneously active, then they both issue commands to the same session.
    56.         /// Although this can cause unintended behavior, it is not expressly forbidden.
    57.         ///
    58.         /// This method is expensive and should not be called frequently.
    59.         /// </summary>
    60.         void WarnIfMultipleARSessions()
    61.         {
    62.             var sessions = FindObjectsOfType<ARSession>();
    63.             if (sessions.Length > 1)
    64.             {
    65.                 // Compile a list of session names
    66.                 string sessionNames = "";
    67.                 foreach (var session in sessions)
    68.                 {
    69.                     sessionNames += string.Format("\t{0}\n", session.name);
    70.                 }
    71.  
    72.                 Debug.LogWarningFormat(
    73.                     "Multiple active AR Sessions found. " +
    74.                     "These will conflict with each other, so " +
    75.                     "you should only have one active ARSession at a time. " +
    76.                     "Found these active sessions:\n{0}", sessionNames);
    77.             }
    78.         }
    79.  
    80.         void OnEnable()
    81.         {
    82. #if DEBUG
    83.             WarnIfMultipleARSessions();
    84. #endif
    85.             ARSubsystemManager.CreateSubsystems();
    86.             StartCoroutine(Initialize());
    87.         }
    88.  
    89.         IEnumerator Initialize()
    90.         {
    91.             // Make sure we've checked for availability
    92.             if (ARSubsystemManager.systemState <= ARSystemState.CheckingAvailability)
    93.                 yield return ARSubsystemManager.CheckAvailability();
    94.                 // Debug txt to see if Subsystem is available
    95.                 Debug.Log("Available Subsystem");
    96.             // Make sure we didn't get disabled while checking for availability
    97.             if (!enabled)
    98.                 yield break;
    99.  
    100.             // Complete install if necessary
    101.             if (((ARSubsystemManager.systemState == ARSystemState.NeedsInstall) && attemptUpdate) ||
    102.                 (ARSubsystemManager.systemState == ARSystemState.Installing))
    103.             {
    104.                 yield return ARSubsystemManager.Install();
    105.                 // Debug txt to see if ARSubsystem needs to be installed
    106.                 Debug.Log("New Subsystem created");
    107.             }
    108.  
    109.             // If we're still enabled and everything is ready, then start.
    110.             if (ARSubsystemManager.systemState == ARSystemState.Ready && enabled)
    111.             {
    112.                 ARSubsystemManager.StartSubsystems();
    113.                 // Debug txt to see if Subsystems Started
    114.                 Debug.Log("Subsystem started");
    115.             }
    116.             else
    117.             {
    118.                 enabled = false;
    119.                 // Debug txt for if Subsystem isn't enabled
    120.                 Debug.Log("Subsystem not enabled");
    121.             }
    122.         }
    123.        
    124.         void OnDisable()
    125.         {
    126.             ARSubsystemManager.StopSubsystems();
    127.             // Debug txt for for Subsystem stopped
    128.             Debug.Log("Subsystem stopped");
    129.         }
    130.        
    131.         void OnDestroy()
    132.         {
    133.             ARSubsystemManager.DestroySubsystems();
    134.             // Debug txt for for Subsystem stopped
    135.             Debug.Log("Subsystem Destroyed");
    136.         }
    137.     }
    138. }
    139.  

    upload_2020-6-16_15-3-40.png
     
  2. apventures

    apventures

    Joined:
    Aug 6, 2018
    Posts:
    24
    I resolved my problem. I had multiple AR packages (Google AR, etc.) and from other third party AR assets that were causing conflicts with AR Foundation and ARCore.