AR按钮离开图像识别目标后仍停留在屏幕上的问题求助
Hey there, let's dig into this issue you're facing with Vuforia and Unity 2017.1.0f2. You mentioned that when you move away from the ImageTarget, the button stays stuck on screen even though it's nested under the ImageTarget in your hierarchy. Let's break down why this might be happening and how to fix it:
Since your Canvas is set to World Space and parented directly under the ImageTarget, it should disappear along with the ImageTarget when tracking is lost. The most likely culprit is that the ImageTarget itself isn't being disabled properly when tracking stops, or the Canvas/Button's active state was manually overridden (breaking inheritance from the parent).
1. Configure the ImageTarget's TrackableBehaviour
This is the most common fix—Vuforia's TrackableBehaviour component has built-in events to handle tracking start/stop:
- Select your
ImageTargetobject in the hierarchy - Locate the
TrackableBehaviourcomponent (it's added automatically by Vuforia) - Under the Event section:
- For
On Tracking Lost: Click the+button, drag the ImageTarget object into the empty slot, then selectGameObject -> SetActiveand set the parameter toFalse - For
On Tracking Found: Do the same, but setSetActivetoTrue
This ensures the entire ImageTarget (and all its children, including the Canvas and Button) is disabled as soon as tracking is lost.
- For
2. Verify Canvas/Button Active State Inheritance
- Check the active checkbox on your
CanvasandButtonobjects. Make sure you haven't manually toggled these—they should inherit their active state from the parent ImageTarget. - If you did manually set their active state before, reset it: Disable the ImageTarget, then re-enable it. This forces the children to sync with the parent's state.
3. Double-Check Canvas World Space Settings (Optional)
While less likely, misconfigured Canvas settings could cause visual artifacts:
- Select the
Canvasobject, check its Transform component. Ensure its position is(0,0,0), rotation(0,0,0), and scale(1,1,1)relative to the ImageTarget. - Confirm the
Plane Distancein the Canvas component is set to a reasonable value (not excessively large, which might make it visible even when the parent is disabled—though this is rare).
4. Fallback: Custom Script for Tracking Control
If the above steps don't work, a simple script can force the ImageTarget to disable on tracking loss:
using UnityEngine; using Vuforia; public class ImageTargetTracker : MonoBehaviour, ITrackableEventHandler { private TrackableBehaviour _trackableBehaviour; void Start() { _trackableBehaviour = GetComponent<TrackableBehaviour>(); if (_trackableBehaviour != null) { _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) { gameObject.SetActive(true); } else { gameObject.SetActive(false); } } }
- Attach this script directly to your
ImageTargetobject. It will listen for Vuforia's tracking events and explicitly enable/disable the entire object.
- Unity 2017.1.0f2 is an older version—make sure your Vuforia version is compatible (Vuforia 7.x is the recommended match for this Unity release).
- If your Button has any custom animations or scripts that control its visibility, double-check that they aren't conflicting with the ImageTarget's active state.
内容的提问来源于stack exchange,提问作者Marc

