Log in or register to post comments

RegisterTrackableEventHandler outdated

January 7, 2020 - 5:32am #1

Hi there.

My goal is to create a marker content dynamically from an assigned prefab when a marker is tracked. So I found a guide (see below) which seems to work for the most parts. However, the method  'RegisterTrackableEventHandler'  from the interface  'ITrackableEventHandler'  are outdated and do not work as they should anymore.

There is a suggested solution for the method which is using the new method  'RegisterOnTrackableStatusChanged'  instead.

But the problem here is that there methods are using different kind of parameters: the old one passes 'this' (the script with the implemented interface 'ITrackableEventHandler' while the new one wants an Action<TrackableBehaviour.StatusChangeResult> as passed parameter, which seems to not exist yet.

 

Is there a clean and simple method to successfully make use of the old function of a newly tracked target without having to create a whole new action?

I am using the latest version of Vuforia (v8.6.7) with Unity 2019.2.

 

Thanks in advance!

 

This is the guide:

https://library.vuforia.com/articles/Solution/Working-with-Vuforia-and-Unity.html#dynamically-add

RegisterTrackableEventHandler outdated

September 21, 2021 - 5:36am #7

I'm using exactly what Revvy shared below.  I've put in bold the lines that now error with Vuforia 10.1.4:

using UnityEngine;

using Vuforia;

using System.Collections;

using static Vuforia.TrackableBehaviour;

public class MyPrefabInstantiator : MonoBehaviour {

  private TrackableBehaviour mTrackableBehaviour;

  public Transform myModelPrefab;

  // Use this for initialization

  void Start ()

  {

    mTrackableBehaviour = GetComponent<TrackableBehaviour>();

    if (mTrackableBehaviour) {

      mTrackableBehaviour.RegisterOnTrackableStatusChanged(OnTrackableStatusChanged);

    }

  }

  // Update is called once per frame

  void Update ()

  {

  }

  public void OnTrackableStateChanged(

    StatusChangeResult obj
)

  {

    if (obj.NewStatus == Status.DETECTED ||

        obj.NewStatus == Status.TRACKED ||

        obj.NewStatus == Status.EXTENDED_TRACKED)

    {

      // Instantiate prefab

    }

  }

}

RegisterTrackableEventHandler outdated

September 21, 2021 - 5:15am #6

Hey,

 

If you could share the code that is creating the errors, I could check what new API calls you should use for this.

Thanks! 

 

Kind regards,

Patrick Scheper

Technical Community Manager

RegisterTrackableEventHandler outdated

September 20, 2021 - 6:10am #5

I was using the below code with no problems, but the latest update to Android 11 had problems with placement in MidAir, so I was troubleshooting by updating Vuforia from 9.8.8 to 10.1.4.  Now I'm getting compiler errors:

Error CS0246 The type or namespace name 'StatusChangeResult' could not be found (are you missing a using directive or an assembly reference?) Assembly-CSharp 

And in reference to mTrackableBehaviour.RegisterOnTrackableStatusChanged(OnTrackableStateChanged); I get:

Error CS1503 Argument 1: cannot convert from 'method group' to 'Action<TargetStatus>' Assembly-CSharp

I can see here: https://library.vuforia.com/project-migration/how-migrate-unity-project that changes have been made to how targets are handled, but in reading the limited examples I don't know how to handle this using the new system.  Any advice would be much appreciated.

RegisterTrackableEventHandler outdated

April 25, 2021 - 2:01pm #4

Since this is closed and I missed it, I opened a new thread, I hope this is okay.

RegisterTrackableEventHandler outdated

July 4, 2020 - 11:03am #3

Revvy wrote:

using UnityEngine;

using Vuforia;

using System.Collections;

using static Vuforia.TrackableBehaviour;

public class MyPrefabInstantiator : MonoBehaviour {

  private TrackableBehaviour mTrackableBehaviour;

  public Transform myModelPrefab;

  // Use this for initialization

  void Start ()

  {

    mTrackableBehaviour = GetComponent<TrackableBehaviour>();

    if (mTrackableBehaviour) {

      mTrackableBehaviour.RegisterOnTrackableStatusChanged(OnTrackableStatusChanged);

    }

  }

  // Update is called once per frame

  void Update ()

  {

  }

  public void OnTrackableStateChanged(

    StatusChangeResult obj)

  {

    if (obj.NewStatus == Status.DETECTED ||

        obj.NewStatus == Status.TRACKED ||

        obj.NewStatus == Status.EXTENDED_TRACKED)

    {

      // Instantiate prefab

    }

  }

}

This solution worked for me! Tks.

RegisterTrackableEventHandler outdated

March 10, 2020 - 2:31am #2

I was struggling with this as well, but it turns out to be pretty easy to change the example to the new method. You just need to pass the OnTrackableStateChanged (or any other function that you create in the class) instead of "this" and make sure the OnTrackableStateChanged takes in a StatusChangeResult as parameter. From there you can access the NewStatus and PreviousStatus of the changed image target.

This is the example code with the new method:

using UnityEngine;

using Vuforia;

using System.Collections;

public class MyPrefabInstantiator : MonoBehaviour {

  private TrackableBehaviour mTrackableBehaviour;

  public Transform myModelPrefab;

  // Use this for initialization

  void Start ()

  {

    mTrackableBehaviour = GetComponent<TrackableBehaviour>();

    if (mTrackableBehaviour) {

      mTrackableBehaviour.RegisterOnTrackableStatusChanged(OnTrackableStatusChanged);

    }

  }

  // Update is called once per frame

  void Update ()

  {

  }

  public void OnTrackableStateChanged(

    StatusChangeResult obj)

  {

    if (obj.NewStatus == Status.DETECTED ||

        obj.NewStatus == Status.TRACKED ||

        obj.NewStatus == Status.EXTENDED_TRACKED)

    {

      // Instantiate prefab

    }

  }

}

Log in or register to post comments