Log in or register to post comments

Detecting a finished Vuforia initialization in Unity before activating content?

May 6, 2019 - 7:34am #1

I have a single scene in my mobile project with multiple pages, one of these is an AR page and I want to initialize Vuforia when entering the page. This is because otherwise the camera permission dialog appears at app launch where the user doesn't yet know what the camera will be used for. I would really prefer the camera permission dialog to appear when entering the AR page, and it seems the automatic Vuforia initialization at app launch is what triggers this.


I've read about delayed Vuforia initialization in Unity from various sources both on this forum and outside. It seems I need to have "Delayed Initialization" set in the Vuforia Configuration file, Vuforia related scripts disabled (VuforiaBehaviour, any image trackers and dynamic dataset loaders) and call VuforiaRuntime.Instance.InitVuforia() where I need it. After that I'm supposed to activate all the Vuforia related scripts and objects. The thing is, to my knowledge there is no way to know when VuforiaRuntime has finished initializing, and infact, it seems VuforiaRuntime.Instance.InitializationState seems to remain in the enum value "INITIALIZING" until I activate the Vuforia content in the scene. Only after that the initialization state seems to switch to "INITIALIZED". There doesn't seem to be any event callbacks for initialization either.


So my question is, after calling VuforiaRuntime.Instance.InitVuforia() how do I know when it's safe to activate VuforiaBehaviour and other AR related content in the scene?

Detecting a finished Vuforia initialization in Unity before activating content?

May 6, 2019 - 8:55am #2


In Unity, there are callbacks for determinin the status of Vuforia initialization:

  • Vuforia has initialized (before trackers and camera are started): VuforiaARController.Instance.RegisterVuforiaInitializedCallback(OnVuforiaInitialized);
  • Vuforia trackers and camera have started: VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted);
  • bool hasVuforiaStarted = VuforiaARController.Instance.HasStarted;

It is important to note that Vuforia *will not* be initialized until a scene that includes an ARCamera is entered.

Vuforia will not try and open the camera unless there is an enabled ARCamera in the scene. Camera permission requests have nothing to do with the Vuforia SDK, other than we initialize the camera and thus need the user's permission to access. They are part of the platform OS's security suite and thus the app needs to handle the logic. Here's an older post, but a good one, on the subject: https://developer.vuforia.com/forum/android/android-60-camera-initialization-failed#comment-53919


Vuforia Engine Support

Log in or register to post comments