Log in or register to post comments

Working VuMark Unity Script

October 19, 2017 - 9:57am #3

I have been working on some AR training and found a lack of usable VuMark scripts. While I am not a programmer, I put something together that works for a proof of concept I am working on, and figured I should post it here for anyone to use and hopefully save you some time.

The script goes onto an empty game object which I will call the "PickerObject" that is a child of the VuMark. Empty game objects are made with the exact VuMark Id names (I made this using numeric VuMark Ids)  These objects are parented to the PickerObject . Anything you then parent to the empty game objects named with the VuMark Ids will become active when the VuMark Id is found. 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Vuforia;

/*

*******Trigger a scene with Matching Vumark Id***********

Place script on a empty game object that is a child of the VuMark.

Create empty game objects with matching VuMark Instance Ids.

inside of those empty game objects put in what you want to be active when the VuMark Id id tracked.

1. Vumark

    a. Empty game object with this script (child of VuMark)

        i. Empty game object- named same as VuMark Id (child of empty game object with script)

            1. Stuff you want to show up whe the Vumark ID is found (Child of empty game object with VuMark Id name)

        i. Empty game object- named same as VuMark Id (child of empty game object with script)

            1. Stuff you want to show up whe the Vumark ID is found (Child of empty game object with VuMark Id name)

    You can make as many as you want. The script will look down the list

    and if it finds a matching VuMarkId and a child of the object the script is on,

    it will make that object active, if not all objects stay inactive

    If you find any errors please email me

    Rich

   



*/

public class VuMarkIdToScene : MonoBehaviour {



    public VuMarkTarget vumark;

    private VuMarkManager mVuMarkManager;

    void Start ()

        {

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

        }

    void Update ()

        {

        foreach (var bhvr in mVuMarkManager.GetActiveBehaviours())

        {

            vumark = bhvr.VuMarkTarget;

            var VuId = vumark.InstanceId;

            print ("Found ID number " + VuId);

            foreach (Transform child in transform)

                {

           

                if (child.name == VuId.ToString())

                    {

                    child.gameObject.SetActive (true);

                    }

                else

                    {

                    child.gameObject.SetActive(false);

                    }

                }

        }

    }

}

Working VuMark Unity Script

January 2, 2018 - 2:31pm #2

Thanks a lot for posting this, it has been difficult to find resources outside of the official core documentation which can be difficult to get working.

Sorry if this is too much if this is a bit of a beginner question, but I'm new to Vuforia, Unity, and Scripting.

I tried implementing your script but got the attached error, any suggestions?

"Assertion failed: Transform has SetIsHierarchyDispatchInterested present when destroying the hierarchy. Systems must deregister themselves in Deactivate."

AttachmentSize
Image icon VuMark_Assertion_Failed.png201.94 KB

Working VuMark Unity Script

July 4, 2018 - 11:47am #1

Thanks for sharing the script @f10r3!

In my case, it worked well only for one image tracked at a time.

When two VuMarks with different IDs were tracked at the same time, both were given the same ID when using the script.

Log in or register to post comments