Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

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

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

  1. andyz


    Jan 5, 2010
    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