Log in or register to post comments

How do you disable object when not in view (target lost)?

May 17, 2017 - 5:45pm #1

Hello. I was trying to find a way to make my AR objects disable when they are not in view (target lost). 

 

The problem I'm having is that I have several animals on cards and have a script that when they are clicked they play an action. When the card is by itself, I can click on it and it plays the correct audio. However, when it's not in view anymore (target lost) and I click - it plays ALL the audio of the cards. Not sure why but is there a way to disable an object when target lost so it ensures that it doesn't conflict with other things? Would really appreciate some help with this.

How do you disable object when not in view (target lost)?

December 24, 2018 - 12:31pm #4

That's correct,

one way to do that is to have a script like the below attached to each Image Tracker object

 

using UnityEngine;

using Vuforia;

//Attach to the image tracker

public class ChildObjectsActivator : MonoBehaviour, ITrackableEventHandler

{

    private TrackableBehaviour trackableBehaviour;

    void Start()

    {

        trackableBehaviour = GetComponent<TrackableBehaviour>();

        if (trackableBehaviour)

            trackableBehaviour.RegisterTrackableEventHandler(this);

    }



    public void OnTrackableStateChanged(

      TrackableBehaviour.Status previousStatus,

      TrackableBehaviour.Status newStatus)

    {

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

            newStatus == TrackableBehaviour.Status.TRACKED ||

            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)

            OnTrackingFound();

        else

            onTrackingLost();

    }

    private void OnTrackingFound()

    {

        if (transform.childCount > 0)

            SetChildrenActive(true);

    }

    private void onTrackingLost()

    {

        if (transform.childCount > 0)

            SetChildrenActive(false);

    }

    private void SetChildrenActive(bool activeState)

    {

        for (int i = 0; i <= transform.childCount; i++)

            transform.GetChild(i++).gameObject.SetActive(activeState);

    }

}

 
 

How do you disable object when not in view (target lost)?

October 10, 2017 - 5:02pm #3

Hello,

You can deactivate your Unity objects be unchecking the box at the root level of the game object. This can also be achieved programmatically by setting the game object's active state to false. This should prevent sound from being played on this object.

Thanks,

-Vuforia Support

How do you disable object when not in view (target lost)?

October 3, 2017 - 2:08pm #2

Hi



I would have the same problem; hope somebody can help us,

Best and thank you :)

 

Log in or register to post comments