Topic has a solution and is locked
Log in or register to post comments

Issues with tracking and Canvas in Unity

August 22, 2016 - 11:29am #1
Topic solved

I'm building a HoloLens application in Unity to demo some AR concepts using Vuforia. I'm trying to display an overlay on top of an image target, but the Unity Canvas does not seem to cooperate with the DefaultTrackableEventHandler.

Usually the tracking found/lost enable/disable logic will work fine for the first couple of iterations of finding/losing the image target. However, it always ends with the canvas not being disabled on tracking lost, and then skipping to the current location of the image target every 3 seconds or so. The canvas remains in the position it was when tracking was lost, and when the target is within view again the canvas will jump to the location of the target after a few seconds. This repeats with this lack of continuous tracking while the canvas is enabled this entire time.

I've tried adding some custom logic to the tracking found/lost events to explicitly enable/disable any Canvas components found in the child hierarchy, but this does not seem to change anything.

Is there something special that I need to do for Canvas to work properly with the tracking found/lost events, or any detail that I could be missing?

Any advice is appreciated,

Thanks

Issues with tracking and Canvas in Unity

December 12, 2016 - 11:25am #9

Oh I solved it, was pretty easy actually. 

I added Canvas stuff:

 

/*==============================================================================

Copyright (c) 2010-2014 Qualcomm Connected Experiences, Inc.

All Rights Reserved.

Confidential and Proprietary - Protected under copyright and other laws.

==============================================================================*/

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);

   Canvas [] canvasComponents = GetComponentsInChildren<Canvas>(true);

            // Enable rendering:

            foreach (Renderer component in rendererComponents)

            {

                component.enabled = true;

            }

            // Enable colliders:

            foreach (Collider component in colliderComponents)

            {

                component.enabled = true;

            }

   foreach (Canvas component in canvasComponents)

   {

    component.enabled = true;

   }



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

        }



        private void OnTrackingLost()

        {

            Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);

            Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);

   Canvas [] canvasComponents = GetComponentsInChildren<Canvas>(true);

            // Disable rendering:

            foreach (Renderer component in rendererComponents)

            {

                component.enabled = false;

            }

            // Disable colliders:

            foreach (Collider component in colliderComponents)

            {

                component.enabled = false;

            }

   foreach (Canvas component in canvasComponents)

   {

    component.enabled = false;

   }

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

        }

        #endregion // PRIVATE_METHODS

    }

}

Issues with tracking and Canvas in Unity

December 12, 2016 - 11:20am #8

I think this has to do with what is enabled and disabled on tracking and on tracking lost.

Vuforia doesn´t disable gameobject, it disables the meshrender component and the collider component. Canvas doesn´t work with meshrenderer, so nothing is disabled (nor enabled). It simply "hops" in place and stays in place even when tracking is lost.

 

So the code needs to be modified to, for example, disable the Canvas component on a Canvas object.

 

I need this too but don´t know where/how to modify the Vuforia code...

Issues with tracking and Canvas in Unity

August 30, 2016 - 11:34am #7

Just posting a follow up in case someone else runs into this:

I was not able to reproduce the bug with smart terrain and extended tracking deadlocking one other. 

The issue with the canvas not disabling open losing tracking, and instead just floating in place at its last tracked position, was not resolved by disabling extended tracking. However, I was able to get this working properly by explicitly enabling/disabling any Canvas components on tracking found/lost. For whatever reason, it appears that the Renderer for the Canvas is either not found properly by GetComponentsInChildren<> or is not enabling/disabling properly, so I had to disable the entire Canvas.

 

Thanks again for the help!

Issues with tracking and Canvas in Unity

August 25, 2016 - 2:42pm #6

Hello,

This is not a known issue. However, Unity's HoloLens Technical Preview and Vuforia's EAP Extension are both in beta, thus, it is likely that bugs will be observed.

I suggest that you try starting from scratch. If you hit the issue again, please document the steps and let me know. I'll use that information to file a bug report.

Thanks


Issues with tracking and Canvas in Unity

August 25, 2016 - 2:20pm #5

Ok, that makes much more sense. However, I'm unable to turn extended tracking off due to the editor/inspector having both the checkboxes for Extended Tracking and Smart Terrain disabled (image on my previous post). Any idea what's going on there? If it's just bugged then I suppose recreating my image target hierarchy would hopefully fix it.

Thanks again!

Issues with tracking and Canvas in Unity

August 25, 2016 - 2:15pm #4

Hello,

Perhaps there is a terminology confusion, so let me define the Extended Tracking feature in hopes of a common understanding.

Extended Tracking utilizes features of the environment to improve tracking performance and sustain tracking even when the target is no longer in view. Here is a more complete article:

https://library.vuforia.com/articles/Training/Extended-Tracking

Note that this article was developed with RGB cameras in mind, so it does not address HoloLens concepts.

So, if your basing an experience on tracking being lost while Extended Tracking is enabled, then it is counter-intuitive to the feature itself as it is meant to continue the experience even after the target is no longer in the camera's FOV.

I suggest that you try your project with ET disabled and see if that provides you with the experience you're looking for.

Thanks.


Issues with tracking and Canvas in Unity

August 25, 2016 - 12:03pm #3

Thanks for the reply!

Yes I do have extended tracking enabled, however my inspector has gotten itself into a confused state where it's become tangled by the restrictions regarding enabling smart terrain and extended tracking (thinks both are enabled/disabled, so I can't toggle either of them), (see attached image), but that's a bug that I can live with.

I suppose my primary confusion is more regarding why the Canvas doesn't deactivate when tracking is lost. It'll work for the first few times (Canvas goes away when target image is moved outside of view), but at some point it'll fail to deactivate, and it's all down hill from that point forward.

 

Any insight into how I can get the Canvas to deactivate every time tracking is lost would be great!

 

 

AttachmentSize
Image icon extendedtracking.png17.3 KB

Issues with tracking and Canvas in Unity

August 25, 2016 - 7:34am #2

Hello,

The Extended Tracking feature behaves a bit differently on HoloLens compared to standard embedded devices. Let me explain.

Once active tracking is lost on the front camera, we use HL to continue tracking (assuming that ET is enabled). During this time we continue to poll the camera to detect the lost target. One that target is found again, we update the pose. Currently, the Vuforia->HL handover when using Extended Tracking is not completely seamless and can result in a "snapping-back" of the augmentation to the target once it is re-detected. This is something we are looking to optimize from our current beta release.

All that being said, the question is: Does your project have Extended Tracking enabled? If so, this could result in the behavior you're observing.

Thanks

Log in or register to post comments