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

Is it just me, or is setting a viewport a giant hassle?

Discussion in 'Editor & General Support' started by Mazer83, Nov 24, 2017.

  1. Mazer83

    Mazer83

    Joined:
    Mar 14, 2016
    Posts:
    19
    I'm developing a top-down strategy game with an orthographic camera, and I don't want the overlay UI's that are on the sides to obscure the view. In an FPS, this isn't a big deal, since if the UI is blocking the view of something, they only have to rotate their view a little to look past it. In a top-down game however, if you get to the edge of the map, UI elements will block your view of things. You need the viewport to be smaller than the screen itself. So I'll just use Camera.rect to set that up. Should be easy, right? Wrong!

    I tried messing around with Camera.rect.x ("Viewport Rect": X in the inspector), try setting it to 0.1. This makes the camera's capture box width about 5% smaller on both sides, why? If you set Y to .1 as well, the width goes back to normal, but now I'm offsetting the viewport upwards too, what if I just want the viewport to be offset to the right? And why does setting x to a number between (0, 1) reduce the size of the capture box, anyway?

    I'm stuck rendering onto a texture, onto a screen-space UI element, which has its own set of problems; the UI element will block clicks/drags on objects, so you have to do your own raycasts. Render to texture seems like the kind of solution you use for reflections, in-game cameras, etc.., not for something as simple as setting a viewport. Am I missing something, or is Unity just poorly designed in this regard?
     
  2. Mazer83

    Mazer83

    Joined:
    Mar 14, 2016
    Posts:
    19
    I was thinking about this, and I realize now that I'm not making sense. If you change the viewport's aspect ratio, of course the capture box will change to match!
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Making the viewport smaller than the screen doesn't seem like a great solution to me...extend the edges of the level so you have non-essential stuff being covered by UI? Make the UI so it doesn't cover stuff? Anyway, yeah, the viewport settings are simple percentages for x/y/width/height and work as expected (well, as I would expect ;) ). I'm not really sure what "capture box" means. Also, not a good idea to change the viewport of the main camera, unless you have another camera rendering something underneath. Otherwise the empty areas are undefined, and render black/garbage/something else depending on device/OS/phase of the moon.

    --Eric