I've checked with the different version of unity, it is working with Unity 2018.2.6f1 Personal which is installed on another laptop. But I've Unity 2018.2.12f1 Personal which gives the error. Is it a unity error?
TargetSearchResult cloud-image-name could not be enabled for tracking. UnityEngine.Debug:LogError(Object) Vuforia.TargetFinder:EnableTracking(TargetSearchResult, GameObject) CloudRec:OnNewSearchResult(TargetSearchResult) (at Assets/Scripts/CloudRec.cs:66) Vuforia.ObjectRecoBehaviour:Update()
Above error indicates the following line as the issue:
m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)m_ObjectTracker.TargetFinder.EnableTracking(targetSearchResult, ImageTargetTemplate.gameObject);
Tech version:
Vuforia version: 7.5.20 | Unity 2018.2.12f1 Personal
Full code is here:
public class CloudRec : MonoBehaviour, ICloudRecoEventHandler
{
private CloudRecoBehaviour mCloudRecoBehaviour;
private bool mIsScanning = false;
private string mTargetMetadata = "";
public ImageTargetBehaviour ImageTargetTemplate;
ObjectTracker m_ObjectTracker;
TargetFinder m_TargetFinder;
// Use this for initialization
void Start()
{
// register this event handler at the cloud reco behaviour
mCloudRecoBehaviour = GetComponent<CloudRecoBehaviour>();
if (mCloudRecoBehaviour)
{
mCloudRecoBehaviour.RegisterEventHandler(this);
}
}
public void OnInitialized()
{
m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
Debug.Log("Cloud Reco initialized");
}
public void OnInitError(TargetFinder.InitState initError)
{
Debug.Log("Cloud Reco init error " + initError.ToString());
}
public void OnUpdateError(TargetFinder.UpdateState updateError)
{
Debug.Log("Cloud Reco update error " + updateError.ToString());
}
public void OnStateChanged(bool scanning)
{
mIsScanning = scanning;
if (scanning)
{
// clear all known trackables
ObjectTracker tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
tracker.TargetFinder.ClearTrackables(false);
}
}
// Here we handle a cloud target recognition event
public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
{
GameObject newImageTarget = Instantiate(ImageTargetTemplate.gameObject) as GameObject;
GameObject augmentation = null;
if (augmentation != null)
augmentation.transform.SetParent(newImageTarget.transform);
if (ImageTargetTemplate)
{
m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)m_ObjectTracker.TargetFinder.EnableTracking(targetSearchResult, ImageTargetTemplate.gameObject);
//ImageTracker imageTracker = TrackerManager.Instance.GetTracker<ImageTracker>();
//ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)imageTracker.TargetFinder.EnableTracking(targetSearchResult, newImageTarget);
}
if (mIsScanning)
{
mCloudRecoBehaviour.CloudRecoEnabled = true;
}
}
// Update is called once per frame
void Update()
{
}
public void OnInitialized(TargetFinder targetFinder)
{
m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
m_TargetFinder = targetFinder;
}
}
After almost a week of the search, I got the error cause. When running with unity the error occurs but when I build to Android or iOS it is working fine. So stopped doubt on the code and it made me think out of the box. So I decided to test on various versions of unity and vuforia with the same machine. It doesn't help to overcome the error. Eventually, I've tested with other machines and I got the error cause. It's because of hardware compatibility.
In my case, I am using mac pro-2009 mid which is not supporting ObjectTracking
But I tested with the same code and same versions of tech on MacBook Air 2017 and Mac Pro mid-2014 it is working fine. So I conclude this as a hardware compatibility issue!