Search Unity

Canvas on an overlay camera doesn't render when base camera target is a render texture.

Discussion in 'Universal Render Pipeline' started by johnburkert, Aug 3, 2020.

  1. johnburkert

    johnburkert

    Joined:
    Mar 28, 2014
    Posts:
    9
    Has anyone else seen this? The canvas is set to "Screen Space - Camera" and renders as expected when the base camera renders to the display. But if you set the base camera to render to a render texture, any canvas on an overlay camera is not rendered. I put an example project up if anyone wants to see what is going on.

    https://github.com/johnburkert/RenderTextureTest
     
  2. Justin_Larrabee

    Justin_Larrabee

    Joined:
    Apr 24, 2018
    Posts:
    106
    I ran into this exact issue. What I had to do was explicitly set the Camera.targetTexture for every overlay camera in my stack. To simplify this I hooked into RenderPipelineManager.beginCameraRendering and just made sure my overlay cameras had the render target set. Alternatively, you could do this when adding them if you are doing that at runtime via the API.
     
  3. Justin_Larrabee

    Justin_Larrabee

    Joined:
    Apr 24, 2018
    Posts:
    106
    As a followup, I have reported this issue via enterprise support and they have reproduced it and have it marked for fix.
     
    johnburkert likes this.
  4. johnburkert

    johnburkert

    Joined:
    Mar 28, 2014
    Posts:
    9
    great! thanks for the info
     
  5. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    270
    Thanks for this info, great thread
     
  6. Bambusz

    Bambusz

    Joined:
    Jan 8, 2021
    Posts:
    6
    Ok, same problem here. So what can you do about it? I can't really seem to figure out Justin's answer. Also in my scene Unity 2021.1.17f1 the overlay camera doesn't render the WORLD SPACE canvas. Pls help
     
  7. fcloss

    fcloss

    Joined:
    Dec 1, 2011
    Posts:
    192
    The suggested solution didn't work for me too, doesn't matter if screen space or world space, canvas does not get rendered into the render texture =Z
     
  8. fcloss

    fcloss

    Joined:
    Dec 1, 2011
    Posts:
    192
    Solution found, it would be good if it was documented somewhere.

    In URP, Unity has the policy to render first the cameras that target a RenderTexture: "In URP, all Cameras that render to Render Textures perform their render loops before all Cameras that render to the screen." (policy for screen rendering)

    So, if you have an overlay camera and a main camera and want to render both to a RT, you shall follow the same logic.

    overlayCamera.targetTexture = renderTexture;
    mainCamera.targetTexture = renderTexture;
    overlayCamera.Render();
    mainCamera.Render();

    This works.