Log in or register to post comments

How to disable vuforia's auto create

January 17, 2018 - 11:38pm #1

I found a issue.

When i create a new scene by unity 2017.3.0.p1.

I found it create complete set vuforia resource when i run. Even there is only camera and light. Main camera has been add vuforia script and all the target has been auto created.

Some scene i don't want enable vuforia. It may be a function scene to select or operate my app's other function, not a AR scene. But it's look's when i enable XR in player setting, every scene become AR scene. 

How to change this operation?

How to disable vuforia's auto create

August 27, 2018 - 1:08am #4

For anyone interested, I found a way to disable this behaviour entirely following this example.

You just add this to a gameobject in your FIRST scene and make sure it executes before anything else (e.g. through the script execution order). It unsubscribes the event method call from the SceneManager to the VuforiaRuntime singleton that adds the behaviour(s) to every main camera in every scene. Once this is done, it should never do this again.

Tested version for Unity 2017.3.1p4

using UnityEngine;
using System.Reflection;
using UnityEngine.SceneManagement;
using System;

public class StopAutoAddVuforia : MonoBehaviour
{
     private void Awake() {
         // https://forum.unity.com/threads/use-ar-camera-vuforia-core-in-individual-scene-not-entire-project.498489/
         try {
             EventInfo evSceneLoaded = typeof(SceneManager).GetEvent("sceneLoaded");
             Type tDelegate = evSceneLoaded.EventHandlerType;

             MethodInfo attachHandler = typeof(Vuforia.VuforiaRuntime).GetMethod("AttachVuforiaToMainCamera", BindingFlags.NonPublic | BindingFlags.Static);

             Delegate d = Delegate.CreateDelegate(tDelegate, attachHandler);
             SceneManager.sceneLoaded -= d as UnityEngine.Events.UnityAction<Scene, LoadSceneMode>;
         } catch (Exception e) {
             Debug.LogWarning("Cant remove the AttachVuforiaToMainCamera action. Execption:" + e.Message);
         }

         Destroy(this);
     }
}

Tested version for Unity 2018.2.4f1

 

using UnityEngine;
using System.Reflection;
using UnityEngine.SceneManagement;
using System;

public class StopAutoAddVuforia : MonoBehaviour
{
     private void Awake() {
         // https://forum.unity.com/threads/use-ar-camera-vuforia-core-in-individual-scene-not-entire-project.498489/
         try {
             EventInfo evSceneLoaded = typeof(SceneManager).GetEvent("sceneLoaded");
             Type tDelegate = evSceneLoaded.EventHandlerType;

             MethodInfo attachHandler = typeof(Vuforia.VuforiaRuntime).GetMethod("AttachVuforiaToMainCamera", BindingFlags.NonPublic | BindingFlags.Instance);

             Delegate d = Delegate.CreateDelegate(typeof(UnityEngine.Events.UnityAction<Scene, LoadSceneMode>), Vuforia.VuforiaRuntime.Instance, attachHandler);
             SceneManager.sceneLoaded -= d as UnityEngine.Events.UnityAction<Scene, LoadSceneMode>;
         } catch (Exception e) {
             Debug.LogError("Cant remove the AttachVuforiaToMainCamera action. Exception " + e.Message);
         }

         Destroy(this);
     }
}

How to disable vuforia's auto create

January 21, 2018 - 7:53pm #3

I hope this will be remove in next version for my part.

It's realy perplex me to choice the vuforia version.

And it conflict in new unity version to use legacy vuforia version.

it's mean that if i want use new version unity, i must endure this function if i need vuforia.

Or, i must use legacy version unity, if i want to do my app by vuforia for free.

How to disable vuforia's auto create

January 19, 2018 - 8:01am #2

Hello ArchiactVuforia,

This is the current expected behaviour of Vuforia in Unity and it is being addressed in a future version. The current way to work around the behaviour is to put an ARCamera in your scene and disable the VuforiaBehaviour that is attached to it. This will ensure Vuforia will not start up and begin scanning/using the camera in this scene.

Apologies for the inconvenience,

Vuforia Support

Log in or register to post comments