1
\$\begingroup\$

I'm working on a vuforia project and would like to be aware when vuforia can no longer detect the object in unity. Is there an easy way to write a script that is executed opon loosing track of an object for a given time?

\$\endgroup\$
1
\$\begingroup\$

You have by default the "DefaultTrackableEventHandler" attached to your Target. This script has a function called "OnTrackingLost()" which is doing exactly what you want to do. Maybe this functionality wasn't available as you asked this question.

\$\endgroup\$
0
\$\begingroup\$

That's correct, one way to do that is to have a script like the below attached to each Image Tracker object

using UnityEngine;
using Vuforia;
//Attach to the image tracker
public class ChildObjectsActivator : MonoBehaviour, ITrackableEventHandler
{
    private TrackableBehaviour trackableBehaviour;
    void Start()
    {
        trackableBehaviour = GetComponent<TrackableBehaviour>();
        if (trackableBehaviour)
            trackableBehaviour.RegisterTrackableEventHandler(this);
    }

    public void OnTrackableStateChanged(
      TrackableBehaviour.Status previousStatus,
      TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED ||
            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
            OnTrackingFound();
        else
            onTrackingLost();
    }
    private void OnTrackingFound()
    {
        if (transform.childCount > 0)
            SetChildrenActive(true);
    }
    private void onTrackingLost()
    {
        if (transform.childCount > 0)
            SetChildrenActive(false);
    }
    private void SetChildrenActive(bool activeState)
    {
        for (int i = 0; i <= transform.childCount; i++)
            transform.GetChild(i++).gameObject.SetActive(activeState);
    }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .