Search Unity

How to make XR Management work with URP?

Discussion in 'AR/VR (XR) Discussion' started by Yandalf, Feb 14, 2020.

  1. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    401
    Hello everyone!

    I'm currently trying to make a minimal VR project using URP but running into a strange snag.
    I first set up the project to use URP correctly with a RenderPipeline Asset, and this works fine.
    Then if I add in the XR Management plugins and install it using the WMR Provider and set the scene up for it, the game view only renders the default skybox without camera rotation applied to it in play mode.
    The render is correct when using a headset, but I'd like this project to work both for VR and Standalone builds.

    When I turn off the Initialize on Startup checkbox in XR Management things work fine for Standalone, but then how do I detect if a headset is connected and need to start up the XR service myself?

    Another problem I encountered in another project (not built by me, but testing out the same setup) is that running their project without a VR headset results in a very upscaled render. Interestingly the camera preview in scene looks a lot better. Anyone know what that could be caused by?
     
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    591
    XR Management is orthogonal to renderer (Built in, URP, HDRP, etc.). That said, support for URP and XR in general should work.

    There is not way to detect if a headset is connected. Basically, if you initialize XR and it fails, there is some issue like non-connected headset involved. However, there is no real way for us to detect if a headset is connected using XR SDK.
     
  3. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    591
    For XR SDK in general, the only way for a camera to track the HMD is to add a Tracked Pose Driver to the camera.
     
  4. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    401
    Hey Joejo!
    Yeah, should work is the keyword here. I am quite concerned that I have to turn off Initialize On Startup in the XR Plugin management settings for my scene to be correctly rendered without an HMD.
    This practically implies separate builds for a VR-enabled executable and a regular executable.

    My setup is a simple scene with a few standard meshes (cube and plane) using a URP/Lit material.
    I then make a Render Pipeline Asset (no settings altered) and set it up in the Project Settings and camera.
    Playing the scene with a headset connected all works as expected, but again, nothing renders and the camera's transform seems to not get applied to the render either when running the scene without a HMD.
    Turn Initialize On Startup off, and everything renders correctly in the game view without an HMD.
    I've tested this both on Unity 2019.3.0f6 and 2019.3.1f1
     
    Last edited: Feb 17, 2020 at 8:55 AM
  5. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    591
  6. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    200
    If I call
    XRGeneralSettings.Instance.Manager.StopSubsystems();
    , I get an URP error :

    IndexOutOfRangeException: renderPassIndex
    UnityEngine.XR.XRDisplaySubsystem.GetRenderPass (System.Int32 renderPassIndex, UnityEngine.XR.XRDisplaySubsystem+XRRenderPass& renderPass) (at <f7eb7b53deab4d9da3876b1762172e6f>:0)
    UnityEngine.Rendering.Universal.UniversalRenderPipeline.CanXRSDKUseSinglePass (UnityEngine.Camera camera) (at Library/PackageCache/com.unity.render-pipelines.universal@7.2.1/Runtime/UniversalRenderPipeline.cs:519)
    UnityEngine.Rendering.Universal.UniversalRenderPipeline.InitializeStackedCameraData (UnityEngine.Camera baseCamera, UnityEngine.Rendering.Universal.UniversalAdditionalCameraData baseAdditionalCameraData, UnityEngine.Rendering.Universal.CameraData& cameraData) (at Library/PackageCache/com.unity.render-pipelines.universal@7.2.1/Runtime/UniversalRenderPipeline.cs:561)
    UnityEngine.Rendering.Universal.UniversalRenderPipeline.InitializeCameraData (UnityEngine.Camera camera, UnityEngine.Rendering.Universal.UniversalAdditionalCameraData additionalCameraData, UnityEngine.Rendering.Universal.CameraData& cameraData) (at Library/PackageCache/com.unity.render-pipelines.universal@7.2.1/Runtime/UniversalRenderPipeline.cs:502)
    UnityEngine.Rendering.Universal.UniversalRenderPipeline.RenderCameraStack (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Camera baseCamera) (at Library/PackageCache/com.unity.render-pipelines.universal@7.2.1/Runtime/UniversalRenderPipeline.cs:398)
    UnityEngine.Rendering.Universal.UniversalRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, UnityEngine.Camera[] cameras) (at Library/PackageCache/com.unity.render-pipelines.universal@7.2.1/Runtime/UniversalRenderPipeline.cs:222)
    UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Camera[] cameras) (at <fb900ccbd717476f91b221d941550640>:0)
    UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, System.IntPtr loopPtr, Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle safety) (at <fb900ccbd717476f91b221d941550640>:0)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr, Boolean&)

    Do you know what could cause this ?
     
  7. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    591
    That looks like a bug. Can you you file an issue with a small repro case and paste the issue is here?
     
  8. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    200
    Done ! Case 1221420
     
  9. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    591
unityunity