Closed Rombond closed 7 months ago
Hi there, the VuforiaConfiguration.Instance.WebCam.DeviceNameSetInEditor
method is only expected to work in the editor and should not be used during runtime. I assume this causes the additional errors you experience and therefor close this ticket. Also note that targeting Windows PCs might cause additional issues and degraded performance as they are not specifically recommended in our recommended devices list.
Like i said in the "Reproducible steps" even without VuforiaConfiguration.Instance.WebCam.DeviceNameSetInEditor
the VuforiaApplication.Instance.Initialize()
doesn't works as exepected.
How can i switch webcams during runtimes or before loading the scene if i have multiples plugged in USB-C into my Surface Pro 8 ?
Hi @Rombond, some additional information about the Exception: the errors you're seeing are due to calling VuforiaApplication.Instance.Deinit()
and VuforiaApplication.Instance.Initialize()
in the same frame.
Vuforia destroys all the ObserverBehaviours
when VuforiaApplication.Instance.Deinit()
is called, but Unity by design doesn't actually destroy objects immediately. When VuforiaApplication.Instance.Initialize()
is called in your code, Unity hasn't completely destroyed everything, so you get those exceptions.
To make sure that Vuforia is correctly deinitialized, you should wait one frame before using VuforiaApplication.Instance.Initialize()
:
private void Update()
{
if (Input.GetKeyDown(KeyCode.U))
{
if (!VuforiaApplication.Instance.IsInitialized) return;
StartCoroutine(ReinitVuforia());
}
}
IEnumerator ReinitVuforia()
{
VuforiaApplication.Instance.Deinit();
yield return null;
VuforiaApplication.Instance.Initialize();
}
Again, on Deinit
Vuforia destroys all the ObserverBehaviours
in the scene, so all the Observerbehaviours
in your scene will not be recreated when Vuforia re-initializes and they will not detect or track.
Our suggestion in this cases is to reload your scene completely after calling Deinit
.
Regarding switching cameras at runtime, that is something that Vuforia does not support out-of-the-box. The only way to do this is to create a custom Driver for your camera. You can find some additional resources at these urls:
Note that, when using a custom Driver, you will have to use a different overload of the VuforiaApplication.Instance.Initialize()
method: VuforiaApplication.Instance.Initialize(string, IntPtr)
Summarize the bug: Can't initialize after a deinit with an image target on an uwp app from Unity.
Observed problem To change webcam I have to Deinit() and Initialize():
After the Initialize i have an "INVALID_TARGET_NAME" error and the choosen webcam stay in the previous states. It does it only on the exported version, if i'm in play mode no error.
Expected result Webcam changes and no error in logs
Reproducible steps Steps to reproduce the behavior:
Affected Vuforia Engine version: I tried 10.19.3 and 10.21.3
Affected platform:
Device or platform logs
Workaround I disable any other webcams than the one that I want to use.