Log in or register to post comments

Canvas always visible when Trackable image target is Lost

May 31, 2016 - 1:38pm #1

hierarchy

ARCamera

Image target

 -Canvas

 

first start Canvas not show (it good)

Track Image target found, canvas show

but if track image target lost, canvas always show.

i was change script and see another tutorial

soo, i am copy script from defaultTrackableEventHandler.cs to canvas.cs

this is script canvas.cs basic from DefaultTrackableEventHandler.cs

and my canvas name is "Information" (If Needed).

 

 

/*==============================================================================
Copyright (c) 2010-2014 Qualcomm Connected Experiences, Inc.
All Rights Reserved.
Confidential and Proprietary - Qualcomm Connected Experiences, Inc.
==============================================================================*/

using UnityEngine;

namespace Vuforia
{
/// <summary>
/// A custom handler that implements the ITrackableEventHandler interface.
/// </summary>
public class canvas : 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()
{
  
   Canvas[] canvasComponents = GetComponentsInChildren<Canvas>(true);
  
   // Enable canvas objects
   foreach (Canvas component in canvasComponents)
   {
    component.enabled = true;
   }

}


private void OnTrackingLost()
{
  
   Canvas[] canvasComponents = GetComponentsInChildren<Canvas>(true);
  
   // Disable canvas objects
   foreach (Canvas component in canvasComponents)
   {
    component.enabled = false;
   }

}

#endregion // PRIVATE_METHODS
}
}

Canvas always visible when Trackable image target is Lost

January 10, 2018 - 10:40am #2

I think you shouldn't copy class implementation with your changes like you did. defaultTrackableEventHandler protected methods are virtual. So you can inherit your class and reimplement method you need. It is more appropriate way.

By the way this problem can be caused by Extended Tracking mode of ImageTarget. Try to disable it.

Log in or register to post comments