Log in or register to post comments

Instance of ObjectTracker is null

July 30, 2015 - 4:51am #18

Hi, I'm trying to create target dynamically and using this i did my code and on building when I set unity player settings to strip to byte code I get null reference error.

NullReferenceException: Object reference not set to an instance of an object

at Load.CreatingDataSet (System.String dataSetName, StorageType storageType) [0x00000] in <filename unknown>:0 

at Load.loadData () [0x00000] in <filename unknown>:0 
at Load.Start () [0x00000] in <filename unknown>:0 
 

Instance of ObjectTracker is null

August 5, 2015 - 3:01pm #17

Instance of ObjectTracker is null

August 10, 2015 - 3:07pm #16

dm3d, I sent you a private message, but I think that tutorial you referred to needs to be updated. I'm seeing the same behavior with the following modified code from your example:

I also see that calls to GetTracker<ObjectTracker> return null even if I explicitly disable the CameraDevice, as shown below.

I'm on Unity 5.1.x, and I see these resutls in the 32 and 64 bit versions of the Unity editor with Vuforia 5.0.5

 

using UnityEngine;
using System.Collections;
using Vuforia;
using System.Collections.Generic;

public class DynamicDataSetLoader : MonoBehaviour
{
	// specify these in Unity Inspector
	public GameObject augmentationObject = null;  // you can use teapot or other object
	public string dataSetName = "";  //  Assets/StreamingAssets/QCAR/DataSetName

	private ObjectTracker _objectTracker;

	// Use this for initialization
	void Start()
	{
		VuforiaBehaviour.Instance.RegisterVuforiaStartedCallback(LoadDataSet);
	}
	
	void LoadDataSet()
	{
		Debug.Log ("Loading Data Set Dynamically");

		Vuforia.CameraDevice.Instance.Stop ();
		if(!Vuforia.CameraDevice.Instance.Deinit())
		{
			Debug.Log ("Could not de-init camera");
		}

		TrackerManager.Instance.InitTracker<ObjectTracker>();
		_objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker> () as ObjectTracker;

		if (!Vuforia.CameraDevice.Instance.Init(CameraDevice.CameraDirection.CAMERA_DEFAULT)) 
		{
			Debug.Log ("Could not re-init camera");
		}
		Vuforia.CameraDevice.Instance.Start ();
		
		DataSet dataSet = _objectTracker.CreateDataSet();
		
		if (dataSet.Load(dataSetName)) {
			
			_objectTracker.Stop();  // stop tracker so that we can add new dataset
			
			if (!_objectTracker.ActivateDataSet(dataSet)) {
				// Note: ImageTracker cannot have more than 100 total targets activated
				Debug.Log("<color=yellow>Failed to Activate DataSet: " + dataSetName + "</color>");
			}
			
			if (!_objectTracker.Start()) {
				Debug.Log("<color=yellow>Tracker Failed to Start.</color>");
			}
			
			int counter = 0;
			
			IEnumerable<TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
			foreach (TrackableBehaviour tb in tbs) {
				if (tb.name == "New Game Object") {
					
					// change generic name to include trackable name
					tb.gameObject.name = ++counter + ":DynamicImageTarget-" + tb.TrackableName;
					
					// add additional script components for trackable
					tb.gameObject.AddComponent<DefaultTrackableEventHandler>();
					tb.gameObject.AddComponent<TurnOffBehaviour>();
					
					if (augmentationObject != null) {
						// instantiate augmentation object and parent to trackable
						GameObject augmentation = (GameObject)GameObject.Instantiate(augmentationObject);
						augmentation.transform.parent = tb.gameObject.transform;
						augmentation.transform.localPosition = new Vector3(0f, 0f, 0f);
						augmentation.transform.localRotation = Quaternion.identity;
						augmentation.transform.localScale = new Vector3(0.005f, 0.005f, 0.005f);
						augmentation.gameObject.SetActive(true);
					} else {
						Debug.Log("<color=yellow>Warning: No augmentation object specified for: " + tb.TrackableName + "</color>");
					}
				}
			}
		} else {
			Debug.LogError("<color=yellow>Failed to load dataset: '" + dataSetName + "'</color>");
		}
	}
}

 

Instance of ObjectTracker is null

August 10, 2015 - 3:16pm #15

Also just for completeness -

 

This happens in the editor, and when I deploy to my Android Device (seen by looking through adb logcat).

If I load a dataset on statup using the Database Load Behaviour (which is what I'm trying NOT to do), that still works.

Instance of ObjectTracker is null

August 10, 2015 - 3:57pm #14

The Tracker is null because you've de-initialized the Camera.

Instance of ObjectTracker is null

August 10, 2015 - 4:21pm #13

But the Intellisence ToolTip around InitTracker<T> says that it will return null if the Camera IS currently initialized. From the code reference:

"Initializing a tracker must not be done when the CameraDevice is initialized or started. This function will return NULL if the tracker of the given type has already been initialized or if the CameraDevice is currently initialized.

Instance of ObjectTracker is null

August 10, 2015 - 4:23pm #12

Just for kicks, I commented out the portion of my code with Stops, DeInits, Inits, and Starts my Camera device. The NullReferenceException still occurs.

void LoadDataSet()
	{
		Debug.Log ("Loading Data Set Dynamically");

		/*Vuforia.CameraDevice.Instance.Stop ();
		if(!Vuforia.CameraDevice.Instance.Deinit())
		{
			Debug.Log ("Could not de-init camera");
		}*/

		TrackerManager.Instance.InitTracker<ObjectTracker>();
		_objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker> () as ObjectTracker;

		/*if (!Vuforia.CameraDevice.Instance.Init(CameraDevice.CameraDirection.CAMERA_DEFAULT)) 
		{
			Debug.Log ("Could not re-init camera");
		}
		Vuforia.CameraDevice.Instance.Start ();*/
		
		DataSet dataSet = _objectTracker.CreateDataSet();
		
		if (dataSet.Load(dataSetName)) {
			
			_objectTracker.Stop();  // stop tracker so that we can add new dataset
			
			if (!_objectTracker.ActivateDataSet(dataSet)) {
				// Note: ImageTracker cannot have more than 100 total targets activated
				Debug.Log("<color=yellow>Failed to Activate DataSet: " + dataSetName + "</color>");
			}
			
			if (!_objectTracker.Start()) {
				Debug.Log("<color=yellow>Tracker Failed to Start.</color>");
			}
			
			int counter = 0;
			
			IEnumerable<TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
			foreach (TrackableBehaviour tb in tbs) {
				if (tb.name == "New Game Object") {
					
					// change generic name to include trackable name
					tb.gameObject.name = ++counter + ":DynamicImageTarget-" + tb.TrackableName;
					
					// add additional script components for trackable
					tb.gameObject.AddComponent<DefaultTrackableEventHandler>();
					tb.gameObject.AddComponent<TurnOffBehaviour>();
					
					if (augmentationObject != null) {
						// instantiate augmentation object and parent to trackable
						GameObject augmentation = (GameObject)GameObject.Instantiate(augmentationObject);
						augmentation.transform.parent = tb.gameObject.transform;
						augmentation.transform.localPosition = new Vector3(0f, 0f, 0f);
						augmentation.transform.localRotation = Quaternion.identity;
						augmentation.transform.localScale = new Vector3(0.005f, 0.005f, 0.005f);
						augmentation.gameObject.SetActive(true);
					} else {
						Debug.Log("<color=yellow>Warning: No augmentation object specified for: " + tb.TrackableName + "</color>");
					}
				}
			}
		} else {
			Debug.LogError("<color=yellow>Failed to load dataset: '" + dataSetName + "'</color>");
		}
	}

 

Instance of ObjectTracker is null

August 10, 2015 - 4:46pm #11

The Tracker is already initialized at the point when the LoadDataSet() method is called. See the API docs for callback:

VuforiaAbstractBehaviour.RegisterVuforiaStartedCallback(Action callback);

"Register for a callback that is invoked after Vuforia has completely started, including camera and trackers. More than one callback can be registered."

 

Instance of ObjectTracker is null

August 10, 2015 - 4:57pm #10

I appreciate your quick responses and patience while I get through this!

OK - In which case I should only retrieve the existing ObjectTracker instead of Initializing a new one...  I believe I've tried that already, but I will modify my LoadDataSet right now and try again...

RESULT: _objectTracker is still null on the final line of pasted code, below.

void LoadDataSet()
	{
		Debug.Log ("Loading Data Set Dynamically");

		/*Vuforia.CameraDevice.Instance.Stop ();
		if(!Vuforia.CameraDevice.Instance.Deinit())
		{
			Debug.Log ("Could not de-init camera");
		}*/

		//TrackerManager.Instance.InitTracker<ObjectTracker>();
		_objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker> () as ObjectTracker;

		/*if (!Vuforia.CameraDevice.Instance.Init(CameraDevice.CameraDirection.CAMERA_DEFAULT)) 
		{
			Debug.Log ("Could not re-init camera");
		}
		Vuforia.CameraDevice.Instance.Start ();*/
		
		DataSet dataSet = _objectTracker.CreateDataSet();

 

Instance of ObjectTracker is null

August 10, 2015 - 5:11pm #9

Try using the code as it appears in my FAQ script:

ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
         
DataSet dataSet = objectTracker.CreateDataSet();

Incorrect:

// Incorrect to use both <T>() and "as" T

GetTracker<ObjectTracker>() as ObjectTracker;

 

Instance of ObjectTracker is null

August 10, 2015 - 5:32pm #8

After opening a fresh project and importing 5.0.5 into it, I have determined that I am a fucking idiot.

My .dll settings on QCARWrapper were all messed up. I also have Oculus plugins in my project which can compete and knock into each other when building for Android.

Fixing my .dll settings resolved the issue. Very sorry to waste your time (and use profanity), but at least you have a troubleshooting path to go down next time someone else is as stupid as me :)

Instance of ObjectTracker is null

November 13, 2015 - 4:15am #7

I'm experiencing the same problem in vuforia 5.0.6 i used these code

    

void Start ()
    {
        qcb = GameObject.Find("ARCamera").GetComponent<VuforiaBehaviour> ();
        
        qcb.RegisterVuforiaStartedCallback (Create);
    }
    
    // Update is called once per frame
    void Update ()
    {
    }

    public void Create ()
    {

        ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();

    }

 

Instance of ObjectTracker is null

February 6, 2016 - 12:53pm #6

Did you fix your issue?

 

if so what solved it?

Instance of ObjectTracker is null

March 7, 2017 - 8:12am #5

I also have this issue with the "Object reference not set.." error.

Instance of ObjectTracker is null

March 14, 2017 - 1:36am #4

Same problem with Vuforia 6.2.10 .

 

In the Editor the tracker works as expected, but in the device ( android ) the tracker is NULL.

 

Kind Regards!

 

Instance of ObjectTracker is null

January 11, 2018 - 5:15am #3

I have seen this problem in many posts but still no solution from vuforia. I have also created a post with the same problem. Lets hope that vuforia can answer and solve the issue. Answers from Vuforia take you to pages that no longer work and to old solutions that also do not work on current sdk. 

Instance of ObjectTracker is null

February 26, 2018 - 10:06am #2

Keep in mind that the ObjectTracker will return null if no camera/tracking device is being used and/or found.

Instance of ObjectTracker is null

March 29, 2019 - 10:55am #1

In my case, my error was to find a instance of ObjectTracker while Vuforia is not completely initialized.

 

To check if Vuforia is initialized you could add a new flag to your project and change it on a function tied to VuforiaBehaviour like:

 

private void Update()

{

    if (VuforiaRuntime.Instance.InitializationState == VuforiaRuntime.InitState.INITIALIZED)

    {

        OnVuforiaEnableCallBack();

    }

}

public void OnVuforiaEnabledCallBack(){

    ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();

}

Log in or register to post comments