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

Unity WebXR构建版本在Quest浏览器中无法渲染(此前运行正常)

Troubleshooting Unity 6.3 WebGL WebXR Loading Stuck on Purple Screen

Hey there, let's work through this frustrating loading issue you're hitting with your Unity VR Web app. Since it worked before and you haven't made code changes that should break it, we'll focus on environmental quirks, hidden debugging angles, and subtle Unity build glitches that might be causing the hang.

1. Rule Out Browser & Environment Issues

  • Test with a fresh browser state: Clear your browser's cache, cookies, and reset site-specific XR permissions (look for "XR" or "Virtual Reality" permissions in your browser's site settings for your app URL). Sometimes cached build files or stale permission states can block XR session initialization.
  • Update/roll back your browser: WebXR support gets frequent updates in Chrome/Edge. Try updating to the latest stable browser version, or if you can, roll back to the exact version where your app worked previously—newer browser updates can introduce unexpected compatibility gaps with Unity's WebXR implementation.
  • Switch devices/browsers: Test your app on a different VR headset or alternative browser (like Firefox Reality if available) to narrow down if the issue is specific to your current setup.

2. Validate Unity Build & WebGL Template Logic

  • Rebuild from scratch: Unity's build cache can sometimes get corrupted even without code changes. Delete your Library folder (back it up first!), then re-export your WebGL build and replace the existing files.
  • Remove WebXR Polyfill temporarily: Modern browsers have solid native WebXR support now. Comment out the polyfill code in your script and rely solely on navigator.xr—it's possible the polyfill is conflicting with Unity 6.3's native WebXR integration.
  • Adjust XR initialization timing: Your current code triggers XR setup right after createUnityInstance resolves. Try delaying the XR session request until Unity signals it's fully ready: add a simple C# script to your scene that sends a message to the frontend once Start() runs, then enable the VR button only after receiving that message. This avoids potential race conditions between Unity's internal XR loading and your frontend script.

3. Dig for Hidden Errors (Since No Warnings Are Showing)

  • Enable WebXR debug logs: In Chrome, go to chrome://flags/#enable-webxr-debug-logs, enable the flag, restart the browser, then filter the DevTools Console for "XR" messages. This often reveals hidden session initialization failures that don't show up as standard errors.
  • Enable Unity WebGL debugging: In Unity's Player Settings > Publishing Settings, check "Enable Debugging" before building. This will output Unity's internal logs to the browser console, which might expose a loading failure in the XR plugin that's not surfaced otherwise.
  • Add error handling to XR session requests: Modify your button click handler to catch session request errors—this could uncover why the session isn't starting:
    enterVRButton.onclick = function () {
        xr.requestSession("immersive-vr").then((session) => {
            xrSession = session;
            enableVR(true);
            xrSession.onend = (event) => {
                enableVR(false);
            };
        }).catch((err) => {
            console.error("XR Session Request Failed:", err);
            alert("VR session failed to start: " + err.message);
        });
    }
    

4. Double-Check Unity XR Configuration

  • Verify XR Plugin Management: Open Project Settings > XR Plugin Management, make sure the WebGL platform has the WebXR plugin enabled, and confirm "Immersive VR" is checked in the plugin's settings. It's rare, but sometimes Unity's configuration can reset silently.
  • Validate the XREnabler Object: Ensure your scene has an active XREnabler object with a public Enable method that accepts an integer parameter. If the object was accidentally deleted or the method name is misspelled, unityInstance.SendMessage will fail silently and could cause the loading hang.

Start with the simplest fixes (clearing cache, rebuilding) first, then work your way through the debugging steps—hidden errors are almost always the culprit when things break without code changes.

内容的提问来源于stack exchange,提问作者Samson Afolabi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.27 10:02:38