You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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:

Possible Root Cause

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).

Step-by-Step Fixes

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 ImageTarget object in the hierarchy
  • Locate the TrackableBehaviour component (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 select GameObject -> SetActive and set the parameter to False
    • For On Tracking Found: Do the same, but set SetActive to True
      This ensures the entire ImageTarget (and all its children, including the Canvas and Button) is disabled as soon as tracking is lost.

2. Verify Canvas/Button Active State Inheritance

  • Check the active checkbox on your Canvas and Button objects. 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 Canvas object, 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 Distance in 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 ImageTarget object. It will listen for Vuforia's tracking events and explicitly enable/disable the entire object.
Quick Notes
  • 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:31:00