Search Unity

Issue with switching scenes

Discussion in 'Vuforia' started by Deleted User, Aug 23, 2018.

  1. Deleted User

    Deleted User

    Guest

    I have a project which is currently made up of 5 scenes.
    An in engine launcher.
    A Mono scene which can go AR.
    A 3 scene which have both AR and VR.

    The mono stage seems to be fine most of the time, we can turn AR on and off and it will still track the marker without errors, this scene simply uses Vuforia and a Image Target Behaviour script to track the marker and when AR mode is disabled, Vuforia and the target behaviour is disabled.

    We have a loading screen for the individual scenes, which has a selection screen when its the AR/VR scenes, and users select HMD or Tripod/Handheld. Which passes off to this function;

    Code (CSharp):
    1.     public static void SetMixedRealityMode(string mode)
    2.     {
    3.         if (mode == "VR")
    4.         {
    5.             VuforiaBehaviour.Instance.enabled = true;
    6.             MixedRealityController.Instance.SetMode(MixedRealityController.Mode.VIEWER_AR);
    7.         }
    8.         else if (mode == "AR")
    9.         {
    10.             VuforiaBehaviour.Instance.enabled = true;
    11. MixedRealityController.Instance.SetMode(MixedRealityController.Mode.HANDHELD_AR);
    12.         }
    13.  
    14.         if (Screen.orientation != ScreenOrientation.LandscapeLeft)
    15.             Screen.orientation = ScreenOrientation.LandscapeLeft;
    16.     }
    For a first instance on AR this works, and until recently this worked for VR but QA brought up a bug with the other scene appearing in VR.

    Now one of the issues I was having earlier and yesterday was that it wouldn't attempt to start vuforia again and then someone suggested doing
    Code (CSharp):
    1. DigitalEyewearARController.Instance.SetViewerActive(true, true)
    when it was no longer being used before disabling vuforia. That fixed that issue, but still in some cases we still get

    Code (csharp):
    1.  
    2. MissingReferenceException: The object of type 'Camera' has been destroyed but you are still trying to access it.
    3. Your script should either check if it is null or you should not destroy the object.
    4. UnityEngine.Component.GetComponentInChildren (System.Type t, Boolean includeInactive) (at C:/buildslave/unity/build/Runtime/Export/Component.bindings.cs:55)
    5. UnityEngine.Component.GetComponentInChildren[BackgroundPlaneBehaviour] () (at C:/buildslave/unity/build/Runtime/Export/Component.bindings.cs:72)
    6. Vuforia.VRDeviceCameraConfiguration..ctor (UnityEngine.Camera cam, Vuforia.VRDeviceController vrDeviceController)
    7. Vuforia.VuforiaVRDeviceCameraConfiguration..ctor (UnityEngine.Camera cam, Vuforia.VRDeviceController vrDeviceController, Single stereoOffset)
    8. Vuforia.DigitalEyewearARController.ConfigureView ()
    9. Vuforia.DigitalEyewearARController.SetViewerActive (Boolean isActive, Boolean deinitCam, Boolean initCam, CameraDirection camDirection, CameraDeviceMode mode)
    10. Vuforia.DigitalEyewearARController.SetViewerActive (Boolean isActive)
    11. Vuforia.MixedRealityController.SetViewer (Boolean viewerPresent)
    12. Vuforia.MixedRealityController.SetViewerAR ()
    13. Vuforia.MixedRealityController.SetMode (Mode mode)
    14. ARVRSwap.SetMixedRealityMode (System.String mode) (at Assets/Scripts/ATStage2Scripts/ARVRSwap.cs:17)
    15. SceneManagerScript.OnSceneLoaded (Scene scene, LoadSceneMode mode) (at Assets/Scripts/GlobalControlScripts/SceneManagerScript.cs:59)
    16. UnityEngine.SceneManagement.SceneManager.Internal_SceneLoaded (Scene scene, LoadSceneMode mode) (at C:/buildslave/unity/build/artifacts/generated/bindings_old/common/Core/SceneManagerBindings.gen.cs:245)
    17.  
    Now the more common error between AR and VR scenes is;
    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. Vuforia.VRDeviceCameraConfiguration..ctor (UnityEngine.Camera cam, Vuforia.VRDeviceController vrDeviceController)
    4. Vuforia.ExternalVRDeviceCameraConfiguration..ctor (UnityEngine.Camera cam, Vuforia.VRDeviceController vrDeviceController)
    5. Vuforia.DigitalEyewearARController.ConfigureView ()
    6. Vuforia.DigitalEyewearARController.SetViewerActive (Boolean isActive, Boolean deinitCam, Boolean initCam, CameraDirection camDirection, CameraDeviceMode mode)
    7. Vuforia.DigitalEyewearARController.SetViewerActive (Boolean isActive, Boolean reinitializeCamera)
    8. ARVRSwap.SetMixedRealityMode (System.String mode) (at Assets/Scripts/ATStage2Scripts/ARVRSwap.cs:12)
    9. SceneManagerScript.OnSceneLoaded (Scene scene, LoadSceneMode mode) (at Assets/Scripts/GlobalControlScripts/SceneManagerScript.cs:59)
    10. UnityEngine.SceneManagement.SceneManager.Internal_SceneLoaded (Scene scene, LoadSceneMode mode) (at C:/buildslave/unity/build/artifacts/generated/bindings_old/common/Core/SceneManagerBindings.gen.cs:245)
    11.  
    This has become quite a bother and a stop to the entire project. From what I have tried in all the singleton classes for reinitialization and resetting vuforia in any attempt just fails and still presented with the error. This prevents being able to track markers again when the error actually appears.

    Since the project has been spread over a few developers there are multiple scenes which manage their AR camera differently. So having a persistent AR Camera isn't possible.
     
  2. Culbertson00

    Culbertson00

    Joined:
    Feb 16, 2017
    Posts:
    1
    Did you ever find a solution for this? I'm having the same error pop up in a current project.
     
  3. Deleted User

    Deleted User

    Guest

    I ended up scrapping what was in place and had to switch to persistent AR and default cameras.
    The AR Camera having vuforia behaviour attached (and my additional behaviours) disabled, then switching active states of default and ar cameras between scenes. This also meant that the trackers had to be persistent in order to keep them associated, but it still required the use of the reassociation function

    Additionally on start up I had to do this
    Code (CSharp):
    1.         //Removing the "AttachVuforiaToMainCamera" functionality from vuforia which is called every time the scene is loaded
    2.         MethodInfo attachHandler = typeof(VuforiaRuntime).GetMethod("AttachVuforiaToMainCamera", BindingFlags.NonPublic | BindingFlags.Instance);
    3.         Delegate d = Delegate.CreateDelegate(typeof(UnityEngine.Events.UnityAction<Scene, LoadSceneMode>), VuforiaRuntime.Instance, attachHandler);
    4.         SceneManager.sceneLoaded -= d as UnityEngine.Events.UnityAction<Scene, LoadSceneMode>;
    So that Vuforia doesn't decide what should be the main camera and where vuforia should be placed. After that theres only the need to use
    Code (CSharp):
    1. Tracker.Instance.GetStateManager().ReassociateTrackables();
    otherwise it complains that they have been destroyed (even though they havent)