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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity 4.6 GUI with rendertexture for upscaling - events in wrong location

Discussion in 'UGUI & TextMesh Pro' started by combatdave1, Dec 17, 2014.

  1. combatdave1

    combatdave1

    Joined:
    Dec 17, 2014
    Posts:
    11
    I am trying to use the new 4.6 Unity GUI system (currently running 4.6.0f3 Pro) to create a bit of UI. I want to make this UI at a resolution of 400x300, then render to a texture which will then be drawn to the screen at a resolution of 800x600 (so double resolution). The problem is this: It doesn't work. The rendering is okay and I can correctly upscale the render texture and have it drawn to the screen, but the UI events aren't received in the correct position, and I can find no way to get around this.

    So:

    • Player resolution is 800x600 Render texture resolution is 400x300
    • Main camera, called "UI Camera" renders to this texture (at 400x300)
    • Canvas set to "Screen Space - Camera" pointing at "UI Camera". Under this is a button which is set to stretch to all sides (so fullscreen, 400x300)
    • A second camera, called "Upscaling Camera".
    • Another canvas set to "Screen Space - Camera" pointing at "Upscaling Camera".
    • This canvas has it's GraphicRaycaster component removed. Under this is a RawImage displaying the render texture.

    When I play, the UI is correctly rendered to the rendertexture, and then displayed on screen at 2x resolution, filling the screen. What is *not* working is the events - the button can only be interacted with when the mouse is in the lower-left quarter of the screen.

    Conceptually, this makes sense. The button is occupying a space from (0, 0) to (400, 300) (starting at the bottom left of the screen), and now my player's resolution is 800x600, this rectangle only covers the bottom left corner. I get that.

    So, with all that said, what can I do to fix this? I can't set the EventCamera on the GraphicRaycaster, so that's out. My next thought was to be somehow fudging the mouse positions. But honestly, I have no clue where to go.

    (And in case somebody has a better way of doing this - I'm looking at a game working in 400x300 resolution which needs to be pixel-perfect. If I were to resize all my UI externally, that would mean that in-engine, they are essentially running on a half-pixel grid. Same goes for using the CanvasScaler component.)

    Cheers for any help.
     
  2. demonixis

    demonixis

    Joined:
    Aug 20, 2013
    Posts:
    185
    Hi,

    I've the same problem here, is anyone know how to solve that ?

    demonixis.
     
  3. fum1h1ro

    fum1h1ro

    Joined:
    Apr 22, 2014
    Posts:
    6
  4. fum1h1ro

    fum1h1ro

    Joined:
    Apr 22, 2014
    Posts:
    6
    Excuse me.

    It has another problem, that layout broken in Editor.
    I'd solved it. But it is more complicated.

    I think, Unity needs to implement 'screen size overrider' to UI.CanvasScaler and UI.GraphicRaycaster.
     
  5. fum1h1ro

    fum1h1ro

    Joined:
    Apr 22, 2014
    Posts:
    6
    https://github.com/fum1h1ro/lowreso_ugui

    This is sample project that problem was solved.

    A point is rendering UI with other camera and rendering to world space by orthographic.
    Sample project permits any size of screen. But not buried margins.