Ortho Camera Consistency

Sorry if this has been brought up else where and I just couldn’t find it.

We are using our own Ortho camera for our 2D/GUI of our game rather than using the GUI built in to Unity, this is because we have certain requirements on our GUI that would just end up being easier if we handled our own windows/events/etc over the immediate mode stuff(Which is great for tools).

Problem is, we will align our objects to be on the edges of the view in our ortho camera and everything looks great, but if the window size changes(Full screen or just larger view or smaller, whatever) the alignment is lost, things lose their position and either get clipped or come in some, seems to only really be happening along the X axis.

I guess I’m just wondering, an ortho camera (Or any camera really) shouldn’t do that right? If it is supposed to do that, how would one going about fixing it, is there a simple trick? I would have assumed if the window size changed the GUI elements in our ortho cam would just transform/skew/stretch with the window but maintain their overall position/anchoring on the screen, thus taking up the same relative space because as far as I knew, the projection would be stretched to fit the client area on render.

Similarly I noticed our main camera will clip if its size changes as well. How do we stop this from happening? In my traditional game programming background, when you go to set up a camera one thing you do is specify its projection matrix, containing the FOV, near/far clip, aspect ratio stuff. If I am remembering correctly, whenever the window size changes, camera’s should rebuild that projection matrix with the new window size, but I doubt that’s happening or it’s happening in a weird way, is there a way to force camera projection matrix to refresh based on new window size or am I way off?

The problem is aspect ratio. Typically you don’t want your game to look squashed when the window is resized, so the projection matrix is set up to keep the horizontal and vertical screen space in the same scale. The result is that if you stretch the screen wider, your view gets wider and you can suddenly see those things that are off the side of the screen.

There are various approaches to fixing this, but it’s always a pain. You might try scaling your objects’ x positions by the aspect ratio, but you’ll have to be careful about where the center of the coordinate system is, etc. In a more mature UI system (Cocoa, qt, etc) you would anchor your UI elements to a part of the screen, and the layout engine would take care of making sure those things move correctly while still maintaining the correct aspect ratio.

I will take a look into the Camera’s aspect ratio stuff to see if I can’t get it working for us. Thanks for your reply.