Log in or register to post comments

Object Stuck on Screen Even After Target is Gone

July 5, 2017 - 2:37pm #1

I have an image target set, and a 3D object set to appear when the camera recognizes the image target. But when i move the image target off screen, the 3D object doesn't disappear. Sometimes it gets stuck at the corner of the screen where the image target went off screen, sometimes if I move the image target too fast it gets stuck where the image used to be. See screenshot of stuck object. 

How do I get the object to only show up when the image target is visible? 

 

Thanks!

 

 

Object Stuck on Screen Even After Target is Gone

July 6, 2017 - 2:18pm #4

If you look at the OnTrackingLost() method, it tells you just how it's hiding your augmentations. It takes all the render components (Mesh Renderer, Sprite Renderer etc.) for the objects that are children of the ImageTarget, puts them into an array, and disables them via a loop. Take a look at the objects that won't disappear and make sure they each have a render component and that they are children of the ImageTarget. 

My guess is the times where it does "disappear" it's actually still rendering but just off screen.  

Another thing you can check is that when the object moves off screen, the "Trackable " + mTrackableBehaviour.TrackableName + " lost" debug text is printed to the console. If it is, you at least know that OnTrackingLost() is being called. 

Object Stuck on Screen Even After Target is Gone

July 6, 2017 - 1:59pm #3

Thanks! Although sometimes it works fine and the model goes away when I move the target offscreen. But sometimes it gets caught and doesn't disappear. 

Here is what my DefaultTrackableEventHandler.cs script currently looks like.

Is it just a bug when the model gets left behind, or is there something wrong with my code?

 

using UnityEngine;

namespace Vuforia
{
    /// <summary>
    /// A custom handler that implements the ITrackableEventHandler interface.
    /// </summary>
    public class DefaultTrackableEventHandler : MonoBehaviour,
                                                ITrackableEventHandler
    {
        #region PRIVATE_MEMBER_VARIABLES

        private TrackableBehaviour mTrackableBehaviour;
  
        #endregion // PRIVATE_MEMBER_VARIABLES

        #region UNTIY_MONOBEHAVIOUR_METHODS
  
        void Start()
        {
            mTrackableBehaviour = GetComponent<TrackableBehaviour>();
            if (mTrackableBehaviour)
            {
                mTrackableBehaviour.RegisterTrackableEventHandler(this);
            }
        }

        #endregion // UNTIY_MONOBEHAVIOUR_METHODS



        #region PUBLIC_METHODS

        /// <summary>
        /// Implementation of the ITrackableEventHandler function called when the
        /// tracking state changes.
        /// </summary>
        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();
            }
        }

        #endregion // PUBLIC_METHODS



        #region PRIVATE_METHODS


        private void OnTrackingFound()
        {
            Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
            Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);

            // Enable rendering:
            foreach (Renderer component in rendererComponents)
            {
                component.enabled = true;
            }

            // Enable colliders:
            foreach (Collider component in colliderComponents)
            {
                component.enabled = true;
            }

            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
        }


        private void OnTrackingLost()
        {
            Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
            Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);

            // Disable rendering:
            foreach (Renderer component in rendererComponents)
            {
                component.enabled = false;
            }

            // Disable colliders:
            foreach (Collider component in colliderComponents)
            {
                component.enabled = false;
            }

            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
        }

        #endregion // PRIVATE_METHODS
    }
} 

Object Stuck on Screen Even After Target is Gone

July 6, 2017 - 9:49am #2

Hello andy2001,

You can turn off the model when the TrackableBehaviour loses its tracking. The sample app has an example of how this is done. The DefaultTrackableEventHandler.cs script handles the simple case of enabling and disabling the model associated with an Image Target when tracking is found and lost.

Thanks,

-Vuforia Support

Log in or register to post comments