Hi @medabit
I think I followed that example from a previous thread someone else posted. However, it does not include directions for how to properly remove previously created Image Target gameobjects from the previous dataset. I have tried swapping the order around, such as destroy before stop or stop before destroy, but the reflection error occurs below each time:
Exception in callback: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> UnityEngine.MissingReferenceException: The object of type 'ImageTargetBehaviour' 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.
at (wrapper managed-to-native) UnityEngine.Behaviour.get_enabled(UnityEngine.Behaviour)
at Vuforia.StateManager+c.b__29_0 (Vuforia.TrackableBehaviour b) [0x00000] in :0
at System.Linq.Enumerable+WhereEnumerableIterator`1[TSource].MoveNext () [0x00037] in :0
at Vuforia.StateManager.UpdateTrackableStates (Vuforia.TrackerData+TrackableResultData[] trackableResults) [0x00106] in :0
at Vuforia.StateManager.UpdateTrackablePoses (UnityEngine.Vector3 positionalOffset, UnityEngine.Quaternion rotationalOffset, Vuforia.TrackerData+TrackableResultData[] trackableResultDataArray, Vuforia.TrackerData+VuMarkTargetResultData[] vuMarkResultDataArray, Vuforia.VuforiaManager+TrackableIdPair originTrackableID, System.Int32 frameIndex, System.Boolean updateTrackableStates) [0x000e3] in :0
at Vuforia.StateManager.UpdateTrackablePoses (UnityEngine.Vector3 positionalOffset, UnityEngine.Quaternion rotationalOffset, Vuforia.TrackerData+TrackableResultData[] trackableResultDataArray, Vuforia.TrackerData+VuMarkTargetResultData[] vuMarkResultDataArray, Vuforia.VuforiaManager+TrackableIdPair originTrackableID, System.Int32 frameIndex) [0x00000] in :0
at Vuforia.VuforiaManager.UpdateTrackers (Vuforia.TrackerData+ManagedFrameState frameState) [0x002c2] in :0
at Vuforia.VuforiaManager.Update (Vuforia.VuforiaScreenOrientation counterRotation, System.Boolean& reapplyOldState) [0x0005e] in :0
at Vuforia.VuforiaARController.UpdateStatePrivate (System.Boolean forceUpdate, System.Boolean reapplyOldState) [0x00051] in :0
at Vuforia.VuforiaARController.UpdateState (System.Boolean forceUpdate, System.Boolean reapplyOldState) [0x0000c] in :0
at Vuforia.DigitalEyewearARController.Update () [0x00000] in :0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in :0
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in :0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in :0
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in :0
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in :0
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in :0
at Vuforia.DelegateHelper.InvokeDelegate (System.Delegate action, System.Object[] args) [0x0000f] in :0
UnityEngine.Debug:LogError (object)
Vuforia.DelegateHelper:InvokeDelegate (System.Delegate,object[])
Vuforia.DelegateHelper:InvokeWithExceptionHandling (System.Action)
Vuforia.VuforiaBehaviour:Update ()
void LoadDataSet(string dataSetName)
{
ObjectTracker objectTracker = TrackerManager.Instance.GetTracker();
DataSet dataSet = objectTracker.CreateDataSet();
if (dataSet.Load(dataSetName))
{
objectTracker.Stop(); // stop tracker so that we can add new dataset
if (itb != null)
foreach (TrackableBehaviour tb in itb)
{ Destroy(tb.gameObject); }
if (!objectTracker.ActivateDataSet(dataSet))
{
// Note: ImageTracker cannot have more than 100 total targets activated
Debug.Log("Failed to Activate DataSet: " + dataSetName + "");
}
if (!objectTracker.Start())
{
Debug.Log("Tracker Failed to Start.");
}
FindITB();
}
else
{
Debug.LogError("Failed to load dataset: '" + dataSetName + "'");
}
}
// finds image targets created and
void FindITB()
{
itb = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
foreach (TrackableBehaviour tb in itb)
{
tb.gameObject.AddComponent();
CreatedImageTargetBehaviour citb = tb.gameObject.GetComponent();
citb.StatusFilter = CreatedImageTargetBehaviour.TrackingStatusFilter.Tracked;
tb.name = tb.TrackableName;
}
}
I am glad I have found your post, I was searching for it for my friend.