Vuforial is a widely used AR toolkit, and if you use it for some time, you will find “Delayed Initialization” for sure.
You would like to try it, right?
Go and do it, cry please, you will see below errors:
Vuforia cannot be started before it is initialized.Please disable Delayed Initialization in the Vuforia configuration or initialize Vuforia manually with the VuforiaRuntime-class.
You would Google this, frustrated, as you can hardly find good answers, and here is why this article comes into play.
Why you prefer the delayed initialization? Simple, your app does not always start from an AR mode, and maybe you have a button , and only when you click button, do you start the target recognition.
A 2nd reason for delayed initialization is the speed, you don’t want to start from the AR mode, and then manually disable it, right?
A 3rd reason, if you start by initialize the AR mode, and then disable it, you will see your camera’s light flashes, though it is very quick. Connect your web cam, run a Vuforia powered app with default settings, you will see that clearly:
Cool. We need you, delayed initialization. But how?
To enable this, first you need turn off a script first:
- Select your ARCamera object
- You will see a “Vuforia Behaviour (Script)” component
- Disable this component
- Enable/Check delayed initialization option in Vuforia Configuration Panel
Run it. Aha, it worked! No errors, no warning, no camera flashes, super fast!
Go and grab a coffee. Emm, let’s turn on the AR mode and start Vuforia again when needed. It is not as easy as imagined:
- Disable/Uncheck delayed initialization programmatically
VuforiaAbstractConfiguration.Instance.Vuforia.DelayedInitialization = false;
- Enable the “Vuforia Behaviour (Script)” component, programmatically
ARCamera.GetComponent<VuforiaBehaviour>().enabled = true;
Cry again, it does not work!
So to manually start/initialize Vuforia again, there is a simple trick, read the aforementioned warning message, you will see:
initialize Vuforia manually with the VuforiaRuntime-class.
So just use below code when you click button, to start the target recognition:
VuforiaRuntime.Instance.InitVuforia();
That is it! Happy coding!
One bonus you will see is that, when you start and then stop the App, if you don’t use delayed initialization, you will see below errors:
If you use delayed initialization, for whatever reasons, the above errors are gone. Weird? Cool? You can tell …