Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity wants to learn about your experiences working on a Unity project today. We'd like to hear from you via this survey.
    Dismiss Notice
  3. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  4. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  5. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Vuforia Overriding OnTrackingFound() in DefaultTrackableEventHandler.cs

Discussion in 'AR' started by JD_FVTC, Mar 26, 2019.

  1. JD_FVTC

    JD_FVTC

    Joined:
    Oct 20, 2017
    Posts:
    39
    I'm trying to override the OnTrackingFound() Function in the DefaultTrackableEventHandler.cs class thats part of the vuforia sdk. How can i do this properly?

    here is the function in DefaultTrackableEventHandler.cs
    Code (CSharp):
    1.    
    2.   public void OnTrackableStateChanged(
    3.         TrackableBehaviour.Status previousStatus,
    4.         TrackableBehaviour.Status newStatus)
    5.     {
    6.         m_PreviousStatus = previousStatus;
    7.         m_NewStatus = newStatus;
    8.  
    9.         if (newStatus == TrackableBehaviour.Status.DETECTED ||
    10.             newStatus == TrackableBehaviour.Status.TRACKED ||
    11.             newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
    12.         {
    13.             Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
    14.             OnTrackingFound();
    15.         }
    16.         else if (previousStatus == TrackableBehaviour.Status.TRACKED &&
    17.                  newStatus == TrackableBehaviour.Status.NO_POSE)
    18.         {
    19.             Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
    20.             OnTrackingLost();
    21.         }
    22.         else
    23.         {
    24.             // For combo of previousStatus=UNKNOWN + newStatus=UNKNOWN|NOT_FOUND
    25.             // Vuforia is starting, but tracking has not been lost or found yet
    26.             // Call OnTrackingLost() to hide the augmentations
    27.             OnTrackingLost();
    28.         }
    29.     }
    30.  
    31.  protected virtual void OnTrackingFound()
    32.     {
    33.         var rendererComponents = GetComponentsInChildren<Renderer>(true);
    34.         var colliderComponents = GetComponentsInChildren<Collider>(true);
    35.         var canvasComponents = GetComponentsInChildren<Canvas>(true);
    36.  
    37.         // Enable rendering:
    38.         foreach (var component in rendererComponents)
    39.             component.enabled = true;
    40.  
    41.         // Enable colliders:
    42.         foreach (var component in colliderComponents)
    43.             component.enabled = true;
    44.  
    45.         // Enable canvas':
    46.         foreach (var component in canvasComponents)
    47.             component.enabled = true;
    48.     }
    49.  
    50.  
    51.  

    I tried writing this with no sucess.
    Code (CSharp):
    1.  
    2. public class StartTheAudio : DefaultTrackableEventHandler
    3. {
    4.  
    5.     public LipSync thescript;
    6.     public LipSyncData thelipSyncData;
    7.     public TextMesh feedback;
    8.  
    9.     private override void OnTrackingFound()
    10.     {
    11. //Never get here
    12.         base.OnTrackingFound();
    13.         thescript = gameObject.GetComponent<LipSync>();
    14.         thescript.Play(thelipSyncData);
    15.         feedback.text += "Played the audio in the function";
    16.     }
    17.     public override void OnTrackableStateChanged(TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus)
    18.     {
    19. //Never get here
    20.     }
    21. }
    22.  
     
  2. albertduranll

    albertduranll

    Joined:
    May 2, 2019
    Posts:
    5
    I'm having the same problem. Did you find any solution that works for you?
     
unityunity