Log in or register to post comments

Dinamically enable/disable Vuforia

March 13, 2018 - 5:14am #1

Hi guys!

I need to build an application that can enable and disable Vuforia, unloading all information related to it (e.g.: tracker, dataset...) and loading other information and other datasets when I decide to enable Vuforia back again.

I am using Vuforia 6.5.22 in Unity 2017.2.0f3 and I am using the "Delayed Initialization" option.

I created prefabs for ARCamera and ImageTragets, with all Vuforia components disabled (e.g.: VuforiaBehaviour, ImageTargetBehaviour...), so I can instantiate them at runtime.

My app starts with ARCamera and ImageTraget prefabs (again, with all Vuforia components disabled) already in the scene, along with a MixedRealityCameraParent game object, because otherwise Vuforia will attach all its components to my main MixedRealityCamera. After my scene starts, I disable the camera component in ARCamera and change its tag to "Untagged", because Vuforia automatically change the tag of ARCamera to "MainCamera", but I do not want that.

Then, when I need to toggle Vuforia, I just disable the camera component of my MixedRealityCamera and change its tag to "Untagged", while I enable the camera component of my ARCamera and change its tag to "MainCamera". After this, I initialize Vuforia with VuforiaRuntime. Then, I enable every Vuforia component in ARCamera and ImageTarget.

So, everything seems to work fine. Based on Vuforia Debug messages, everything seems to be initialized and deinitialized correctly. The problem arises when I try to re-enable Vuforia back again, after the first time. The error I get is "Could not start tracker". For this, I tried to explicitly stop the ObjectTracker, deactivate my DataSets, and deinitialize the ObjectTracker with TrackerManager (I do all this before deinitialize Vuforia with VuforiaRuntime, but after disabling all its components in ARCamera and ImageTraget). When I tried this solution, it seems that Vuforia cannot access the Webcam, because I see only a black screen in Unity Editor, but nothing crashes. Instead, when I try to disable Vuforia again (the second time) I get a nullReferenceException when I try to access my active DataSets. Therefore, I think that Vuforia is not re-initialized correctly.

To summarise, I do the following:

App starts: Disable ARCamera camera component and change tag 

Enable Vuforia: Enable ARCamera camera component and change tag -> Initialize Vuforia with VuforiaRuntime -> Enable all Vuforia components in ARCamera and ImageTraget

Disable Vuforia: Disable ARCamera camera component and change tag (for getting back to my MixedRealityCamera) -> Disable all Vuforia components in ARCamera and ImageTraget -> Stop ObjectTracker -> Deactivate active DataSets -> Deinitialize ObjectTracker with TrackerManager -> Deinitialize Vuforia with VuforiaRuntime

Remeber, when I do this the first time everything works. After that, it doesn't...

Last thing, I forgot: all the image target gameobjects that Vuforia instantiates when it is enabled do not go away when I try to disable Vuforia, and I do not really know why.

Can anybody help me, please? Anybody knows the correct pipeline of init/deinit to implement? Thanks!

Dinamically enable/disable Vuforia

October 16, 2018 - 7:51am #2

I have the same issue. Could you fix it? Thank you.

Log in or register to post comments