Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Floating World space UI when using Camera Stacking in URP

Discussion in 'Universal Render Pipeline' started by boruds, Jul 16, 2021.

  1. boruds

    boruds

    Joined:
    Aug 7, 2020
    Posts:
    28
    I have an app that uses AR Foundation and my main camera is an AR Camera.
    I have world space UI that gets rendered on walls which overlaps with the virtual objects placed on the walls.
    I want to text to be rendered on top of the planes placed in the scene. So I put the UI on a separate camera layer and then stacked the camera over the base camera. This gives me the right result and the UI is over the world space geometry, but I am noticing this weird behavior where the UI Floats over the worlds space geometry and not staying at the exact same spot it is supposed to be. The floating behavior happens when the camera is tilted, it is almost like a parallax effect.

    My UI camera is the child of the AR Camera. The AR Camera is the main camera and the base camera. The UI camera is the overlay camera which is then added to the base camera stack.
    What might be causing this parallax? The position and rotation of my UI Camera is zero and it's parent is the ar camera.
     
    VRagments likes this.
  2. jensVrag

    jensVrag

    Joined:
    Aug 9, 2019
    Posts:
    13
    This exact thing is happening in our project as well. Both cameras have same settings and are basically copies of one another, with the WorldUI camera set to overlay, added to the Main camera's stack, and culling to UI only.
     
    VRagments likes this.
  3. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    camera stacking does not work in URP and has loads of problems. i fought with for a year before deciding to just use one camera.
     
  4. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    1,763
    Since this popped as one of the first search results for URP camera stacking issues with Worldspace UI, here's how I got it working.
    • Both cameras need to have identical settings - position, size, everything. Best achieved by copying the Camera component of Main camera, then pasting values on the UI camera.
    • Main Camera is set as Base with culling mask set to render all except UI.
    • UI Camera set as Overlay in the stack with culling mask set to render only UI.
    • There are two camera controller scripts - one for the main camera that takes care of player input and another on UI camera that listens to any changes made on the main camera. The implementation details change depending on what exactly is controlling the main camera, but since I'm not using Cinemachine, I simply have UI camera update its position and size in LateUpdate() to match the Main camera. I believe Cinemachine has some events you can subscribe to for this.
    I'm on Unity 2021.3.16 and URP 12.1.8
     
    Last edited: Jan 8, 2023