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.

Bug canvas rect wrong when camera set to RenderTexture, 2019 break?

Discussion in 'UGUI & TextMesh Pro' started by andyz, Nov 26, 2020.

  1. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,050
    Trying to fix a UI issue that was OK in 2018 but in 2019 LTS seems to be an issue.
    If you do camera.targetTexture = someRenderTexture;
    then the camera will immediately have a new pixel width/height based on the render texture, but if I look at a UI canvas assigned to that camera if will currently have a canvas rect based on the screen size & aspect ratio (screen space canvas, scale with screen).
    The UI does not seem to work properly here as it is wrongly scaled when drawn in to render texture - appears to use render texture resolution not virtual resolution from canvas scalar

    How can I immediately update that canvas rect & scalar to fix?

    TLDR if want to change camera settings and render UI for 1 frame then canvasRect.rect for UI canvas will be wrong in the first frame (updated at frame end?) and you may have difficulty placing things over say world positions (non-screen-aligned positions)
     
    Last edited: Nov 26, 2020