Log in or register to post comments

Can't get simultaneous VuMarks working

August 15, 2019 - 2:48pm #1

Hello, I'm using the following script to display a different model depending on the encoded data of the VuMark.  I have basically followed this tutorial https://youtu.be/NDtRvgC-cfw 

Here is the code: 

### csharp

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Vuforia;

public class VuMarkTrackerBehavior : MonoBehaviour, ITrackableEventHandler

{

    public GameObject[] models;

    TrackableBehaviour vuMark_TrackableBehavior;

    VuMarkManager vuMark_Manager;

    void Start()

    {

        foreach(var model in models)

        {

            model.gameObject.SetActive(false);

        }

        vuMark_TrackableBehavior = GetComponent<TrackableBehaviour>();

       

        if (vuMark_TrackableBehavior != null)

        {

            vuMark_TrackableBehavior.RegisterTrackableEventHandler(this);

        }

        vuMark_Manager = TrackerManager.Instance.GetStateManager().GetVuMarkManager();

    }

    public void OnTrackableStateChanged(TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus)

    {

        Debug.Log("Trackable " + vuMark_TrackableBehavior.name +

                  " " + vuMark_TrackableBehavior.CurrentStatus +

                  " -- " + vuMark_TrackableBehavior.CurrentStatusInfo);

        if (newStatus == TrackableBehaviour.Status.DETECTED ||

            newStatus == TrackableBehaviour.Status.TRACKED ||

            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)

        {

            OnTrackerFound();

        }

        else if(previousStatus == TrackableBehaviour.Status.TRACKED && newStatus == TrackableBehaviour.Status.NO_POSE)

        {

            OnTrackerLost();

        }

    }

    void OnTrackerFound()

    {

        foreach (var item in vuMark_Manager.GetActiveBehaviours())

        {

            int id = System.Convert.ToInt32(item.VuMarkTarget.InstanceId.NumericValue);

            models[id].gameObject.SetActive(true);

        }

    }

    void OnTrackerLost()

    {

        foreach (var item in vuMark_Manager.GetActiveBehaviours())

        {

            int id = System.Convert.ToInt32(item.VuMarkTarget.InstanceId.NumericValue);

            models[id].gameObject.SetActive(false);

        }

    }

}

###

Next I set "Max Simultaneous Tracked Images" to 4 and then hit "Play"

The result is that when holding up 1 VuMark I see the model as expected.  However, if I then hold up and 2nd VuMark I get the following error:

NullReferenceException: Object reference not set to an instance of an object

VuMarkTrackerBehavior.OnTrackerFound () (at Assets/AA/Scripts/VuMarkTrackerBehavior.cs:68)

VuMarkTrackerBehavior.OnTrackableStateChanged (Vuforia.TrackableBehaviour+Status previousStatus, Vuforia.TrackableBehaviour+Status newStatus) (at Assets/AA/Scripts/VuMarkTrackerBehavior.cs:57)

Vuforia.TrackableBehaviour.RegisterTrackableEventHandler (Vuforia.ITrackableEventHandler trackableEventHandler) (at <21bfe61d2ac241f6a9131b858645aad9>:0)

VuMarkTrackerBehavior.Start () (at Assets/AA/Scripts/VuMarkTrackerBehavior.cs:25)

This refers to the line "foreach (var item in vuMark_Manager.GetActiveBehaviours())"

Additionally, in the scene hierarchy a Clone of the VuMark object is instantiated.  Looks like VuMark(Clone).

Please advise on what's needed to track multiple VuMarks so that I can use the encoded data to determine which model to display for that VuMark.

Thank you.

AttachmentSize
Image icon Annotation 2019-08-15 174747.png202.13 KB

Can't get simultaneous VuMarks working

August 16, 2019 - 11:09am #3

Hello,

The Vuforia Engine Core Samples, available for free on the Unity Asset Store, demonstrate the simultaneous tracking of multiple VuMarks. I suggest that you plug your VuMark device database into our samples for testing, and review our sample scripts for best practices.

The reference video you provided looks like they leveraged our samples to produce the app being demonstrated.

Thanks,

Vuforia Engine Support

Can't get simultaneous VuMarks working

August 16, 2019 - 7:38am #2

BTW - This video shows basically what I would like to accomplish...  Please help!

https://www.youtube.com/watch?v=gUlX6m_pxQ0

Log in or register to post comments