Log in or register to post comments

Preventing VuMark Child Cloning

March 7, 2018 - 8:23am #1

I am currently testing some things with VuMarks in Unity, part of which includes moving an object from one VuMark to another when a new one is tracked. The issue I am currently running into is that when the new VuMark is detected, the current VuMark is cloned to represent it, including the child object. So instead of having one object moving between two VuMarks, I have two objects, one on each mark.

If I'm understanding correctly, the object must be childed to the VuMark in order to appear. When a new VuMark is tracked, it is represented by cloning the hierarchy of the VuMark in my scene, which contains the object, resulting in it also being cloned. Is there a way to prevent the children of a VuMark from being cloned when a new mark is tracked, or a way for my object to be visible without being a child of the VuMark?

I am using Unity 2017.3.1f1, and the VuMarks are two instances of the same template.

Preventing VuMark Child Cloning

March 12, 2018 - 7:07am #6

I too found this problem while trying to spawn several instances of a VuMark.

You do not have to track this every frame, but only when the VuMark identifies a mark. After trying different solutions to this problem, I found a suitable one for my project:

Upon identifying a mark, a conditional check in the OnTrackingFound() function in DefaultTrackableEventHandler was triggered, in which the id/code of the identified mark was parsed and suitable actions took place.

In my case, I have several child GameObjects with the same name as the id/code for the VuMarks, and i just SetActive(true) the child which name that correspond to the identified mark. All the other are SetAcive(false)'d.

Example and information:

*1 If VuMarkCode "child0", "child1", or "child2" is identified, show it (only one of them per instance) and hide everything else for this instance. If vuforia is configured to handle multiple marks, all of these childs can be triggered simultaneusly.

*2 If finding "other0" or "other1", childs does not get spawned, but these are recognised and can be used for things such as scene transitions and other useful thunks.

*3 All children will automagically be deactivated whenever the mark is lost, but the state of the object will be retained, since Vuforia does not delete any instances that are deactivated. However! The state if only valid for the object which instance was active. If the state should be stored over all object of that kind, the information will have to be transferred to some other object.

*4 All children must be present in the Unity Hierarchy tree view when application is executed. But only those which are set to display are displayed at runtime when the correct VuMark is shown.

Code:

// Called from OnTrackingFound()

public void ActivateChildByVuMarkId()

// Check if a mark has been identified, returns null if there are no marks active in this instance. Might not strictly be necessary since this is only called when a mark is found, but useful if called from Update (Not recommended).

if(GetComponent<VuMarkBehaviour>().VuMarkTarget == null)

    return;

// Get the code/id of the identified VuMarkInstance

string vuMarkCode = GetComponent<VuMarkBehaviour>().VuMarkTarget.InstanceId.ToString();

switch(vuMarkCode) {

case "child0":

case "child1":

case "child2":

    foreach(Transform child in transform) {

        if(child.gameObject.name.Equals(vuMarkCode)) {

            child.gameObject.SetActive(true);

        } else {

            child.gameObject.SetActive(false);

        }

    }

    break;

case "other0":

// Do something else

    break;

case "other1":

// Yet something else to do

    break;

default:

    break;

}

//Sorry for the code formatting, seems the code-block tags did disturbing things with the code..

Best regards Erik

Preventing VuMark Child Cloning

March 7, 2018 - 11:36am #5

I am currently parenting the object to the mark at runtime, but since it is in the mark's hierarchy when the new mark is detected, it is being clones into the new mark. I believe the only solution would be to track the mark every frame, please correct me if I'm wrong.

Preventing VuMark Child Cloning

March 7, 2018 - 11:26am #4

This is correct. Though to avoid the issue initially described in this post I'd recommend parenting the object to the VuMark at runtime. This will give you exact control over what you are doing with the augmentation and will prevent more objects from spawning when you detect more targets.

Thanks,

Vuforia Support

Preventing VuMark Child Cloning

March 7, 2018 - 10:59am #3

If I wanted the item to track along with the VuMark however, am I correct in assuming my only two options are to child it to the mark, or update it to the mark's position each frame?

Preventing VuMark Child Cloning

March 7, 2018 - 9:44am #2

Hello MattW2013,

There is no way to prevent this behaviour as that is how Vuforia handles detecting multiple instances of a VuMark.

However, you do not have to make an augmentation a child of the VuMark in order to display it. You can instead have your model defined elsewhere in the scene and upon detection of you VuMark, parent it (or simply move it) to that VuMark. Then you can do whatever behaviour is necessary when both VuMarks are detected. When losing tracking of either or both you can have additional logic to place your model back to wherever it was initially.

Let me know if you have any further questions about this.

Thanks,

Vuforia Support

Log in or register to post comments