Log in or register to post comments

ARCamera KeepAlive Woes

February 5, 2014 - 2:49am #1


this is our scenario:

- We have some nonVuforia Scenes, one will Load a Vuforia Scene

- In this Scene i have a ARCamera wich loads a Dataset for Imagetargets. There are 2 more Cameras in there, one is rendering nGui, another one rendering additional stuff.

- I created so far 2 imageTargets with a modified Tracking behavior. They shall only load another scene, once they are beeing tracked.

- To optimize i want to keep some Structures alive, as they are all the same for all other vuforia scenes:

- the Ngui setUp

- the other camera

- and the ARCamera


But the ARCamera is a no go. When i set it to keepAlive it will disable my 2 empty imageMarkerTrackables and for some reason create new ones, which are named as "Empty Game Object" and have "Image Target Behaviour" Component, but with attributes set to nothing, (huh? Why is that).

So those 2 Trackables wont be tracked, and i cannot load other scenes.

Second attempt:

Write a short Component which just sets ARCamera to DontDestroy on load. (The to be loaded scene has no ARCamera).

This works and my Trackables remain untouched.

But after the next scene loads, i this Error:

MissingReferenceException: The object of type 'Camera' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
TextureRenderer.Render ()
WebCamImpl.GetPixels32AndBufferFrame (Int32 frameIndex)
QCARManagerImpl.InjectCameraFrame ()
QCARManagerImpl.Update (ScreenOrientation counterRotation, CameraDeviceMode deviceMode, .VideoModeData& videoMode)
QCARAbstractBehaviour.Update ()
The only way i could get my idea to work was to not keep the Camera alive, also dont set it to DontDestroyOnLoad and instead have an ARCamera in every scene.
But this leads to a short black Video Background on Level Change and more things need to load again and init again.
i also tried to use this script from a related Vuforia site, but it doesnt help. Had to change Start to Awake to do something, but then it would just destroy my imagetargets onLoad of the first Vuforia Scene, where it should definatly not delete anything. Only in later scenes.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
/// <summary>
/// Example script for ILoadLevelEventHandler which destroys all word behaviours when
/// loading a new level
/// </summary>
public class TrackableBehaviorKeepAliveHandling : MonoBehaviour, ILoadLevelEventHandler {
	// these trackable behaviours will be deleted on scene change 
	// so that the ones defined in the next scene are used instead.
	public DataSetTrackableBehaviour[] TrackableBehavioursToDeleteOnSceneChange;

	/// <summary>
	/// register for events at the KeepAliveBehaviour
	/// </summary>
	private void Awake() {
		var keepAlive = KeepAliveBehaviour.Instance;
		if (keepAlive != null) {
			Debug.LogWarning("TrackableBehaviorKeepAliveHandling Registers Events");

	/// <summary>
	/// Iterates all trackable behaviours that are kept alive and destroys word behaviours
	/// </summary>
	public void OnLevelLoaded(IEnumerable<TrackableBehaviour> keptAliveTrackables) {
		var stateManager = TrackerManager.Instance.GetStateManager();
		Debug.Log("TrackableBehaviorKeepAliveHandling: OnLevelLoaded:");
		foreach (var behaviour in TrackableBehavioursToDeleteOnSceneChange) {

			if (keptAliveTrackables.Contains(behaviour) && behaviour.Trackable != null) {
				Debug.Log("TrackableBehaviorKeepAliveHandling: OnLevelLoaded: Deleting Trackable " + behaviour.Trackable.Name + "in LoadLevelEventHandler.");
	/// <summary>
	/// Deletes all trackable behaviours that were disabled as duplicates of kept
	/// alive trackables
	/// </summary>
	public void OnDuplicateTrackablesDisabled(IEnumerable<TrackableBehaviour>disabledTrackables) {
		Debug.Log("TrackableBehaviorKeepAliveHandling: OnDuplicateTrackablesDisabled:");
		foreach (TrackableBehaviour trackableBehaviour in disabledTrackables) {
			Debug.Log("TrackableBehaviorKeepAliveHandling: OnDuplicateTrackablesDisabled: " + trackableBehaviour.gameObject.name);


Any Idea???



ARCamera KeepAlive Woes

February 5, 2014 - 1:51pm #5

yes i did that, but it did not make any difference, as i remember.

(under the condition that i do not start with vuforia stuff, but have empty scenes before. If i start directly with a vuforia scene, it seemed to work)

ARCamera KeepAlive Woes

February 5, 2014 - 5:19am #4

Ok, glad to hear that you have found the solution.

But you should also be able to put the ARCamera and the Trackables in the same scene; to do that, however, you would need to enable the "Keep Trackable Prefabs Alive" checkbox,   which appears in the ARCamera Inspector, right under the "Keep AR Camera Alive" checkbox. Have you tried that ?


ARCamera KeepAlive Woes

February 5, 2014 - 4:48am #3

Yes, i have 1 ARCamera and two imageMarkerTrackers there.


Anyways i guess i found a workaround by doing this:


1. Create one more scene with only an ARCamera and no imageMarker Gameobjects.

2. Set AR Camera to keepalive

3. Immideately after this scene was loaded, load the scene with the two markers but no ARCamera and do the rest from there.


Camera is always there now and my imagemarkers are not beeing disabled and duplicated any more.


Is this the supposed way to do it? Seems awkward...

ARCamera KeepAlive Woes

February 5, 2014 - 4:17am #2

Hi, I'm trying to understand what you are doing exactly,

but I'm not fully clear.

Could you clarify this statement:

I created so far 2 imageTargets with a modified Tracking behavior. They shall only load another scene, once they are beeing tracked.

What do you mean exactly ?

Do you have the ARCamera and the 2 Trackables in the same scene ? or in separate scenes ?

Could you explain exactly what each scene is supposed to contain?


Log in or register to post comments