HoloLens and Unity tip #007 – Vuforia behaviour off and on in your HoloLens app

In short Vuforia allows you to recognize 2D or 3D objects inside your application and allows you to map exactly at that position a part of your scene. It uses the camera of your device to do that. It actually locks the camera, since the camera can only be used by one process. In case of HoloLens you are not able to use the camera for other purposes like cognitive services, demonstrations via video streaming, etc. The other issue is that it will use some resources on the background because the process of recognition by Vuforia engine is still active. This can influence the performance of your app.

In older releases of Unity were you had to install Vuforia separately, Vuforia was enabled per scene. Since Vuforia is fully integrated in Unity, it can only be enabled for all the scenes together.

So it is important to turn the behaviour of Vuforia off when it is not needed. There are a numerous of Vuforia classes which allows you to configure Vuforia. And in most cases it is not actually clear how you can turn the behaviour  off or on. Some of the methods even cause Vuforia to become unstable.

But turning the behaviour of Vuforia on or off is very simple. If you have Vuforia enabled in your project it configures some default stuff and adds a specific component to your camera. Open the camera in your hierarchy.

Vuforia-camera

You will notice a component added called “Vuforia Behaviour”. That component controls the behaviour of Vuforia when the app is running.

vuforia-camera-behavior

If you want to turn the behaviour on or off you can simply enable or disable the component. Doing this in code is even simpler. There is an instance of the VuforiaBehaviour object available. By setting the property enabled = true or enabled = false will turn the behavior on and off.

   
    private void SetVuforiaActive(bool vuforiaState)
    {
        VuforiaBehaviour.Instance.enabled = vuforiaState;
    }

As soon as the behaviour is turned off you can use the camera for other purposes and is the Vuforia engine not using any other resources.

The post HoloLens and Unity tip #007 – Vuforia behaviour off and on in your HoloLens app appeared first on 365 XR Blog.