1

I am facing the following problem: when I want to place an object in the Scene it moves around, I need it to stay in its place so it must be an anchor object.

Unfortunately, we can't anchor an object in Vuforia without Using Plane Ground detection.

Moreover after "Enabling Plane Ground Detection", the augmented object appear and never gets lost and the function "onTrackingLost" never triggered. It seems that this function is not automatically being Called and not working!

How can we solve this issue, please ?!

Qusai Azzam
  • 465
  • 4
  • 19
  • When do you want object to get lost? Because when you use ground planes you automatically use `Extended Tracking`. So the object will be tracked even if it is not in the frame. Also if you would like to anchor object at arbitrary places i would recommend ARCore it is more flexible than Vuforia – Ali Kanat Feb 13 '19 at 09:23
  • You can also look at [this](https://stackoverflow.com/questions/52584824/gameobject-not-destroying-when-image-target-lost-vuforia-hololens) if that is what you want – Ali Kanat Feb 13 '19 at 09:23

1 Answers1

0

You could detach the object from the vuforia target - making it not a child but instead set it somewhere else in the hierachy - and only move it to the correct coordinates OnTargetFound.

Add e.g. a UnityEvent<Transform> like (this goes to the vuforia target)

[system.Serializable]
public class TransformEvent : UnityEvent<TargetFoundEventHandler>
{
}

public class TargetFoundEventHandler : DefaultTrackableEventHandler
{
    public TransformEvent onTrackingFound;

    protected override void OnTrackingFound()
    {
        onTrackingFound.Invoke(transform);
    }
}

you can use that to reference callbacks (similar to the onClick of Buttons) but those methods have to expect a TargetFoundEventHandler parameter like (this goes to the object to place)

public class PlaceMeOnTarget()
{
    public void PlaceOnTarget(TargetFoundEventHandler target)
    {
        transform.SetPositionAndRotation(target.transform.position, target.transform.rotation);

        // optinally remove the callback so this object
        // will not be placed elsewhere
        target.onTrackingFound.RemoveListener(PlaceOnTarget);
    }
}
derHugo
  • 83,094
  • 9
  • 75
  • 115
  • thanks for the answer, my problem is in the OnTrackingLost function that never automatically triggered anymore! when the OnTrackingLost is Being Called if the Ground Plane Detection is being Enabled? – Qusai Azzam Feb 11 '19 at 14:09
  • I don't know .. I just provided you an answer with a workaround which doesn't need `OnTrackingLost` – derHugo Feb 11 '19 at 14:09
  • thanks for your rapid answer, Actually, the problem is Vuforia doesn't automatically trigger the OnTrackingLost Function After Enabling Ground Detection. – Qusai Azzam Feb 11 '19 at 15:29