Camera.rect not working properly after build

In my application I have logic to update camera.rect so that cut-scenes are played with a letterbox effect (zoomed with black bars at the top and bottom) to give a more cinematic experience. I am using the following code (as specified in the Unity documentation):

//*** Make the cut-scene letterboxed
float scaleHeight=1.0f/2.0f;
Rect rect=camera.rect;

Everything works fine within Unity.

When I build the project (Windows app) the aspect ratio is changed properly and I see the desired view in the center of the screen.

The problem is that instead of displaying black bars in the “dead areas” at the top and bottom of the view: the remnants of the top and bottom of the scene from the old apsect ratio are still displayed. It looks like Unity isn’t clearing the old draw buffer or something?

Any ideas for (1) why this works properly in Unity but not in the built version and (2) any workarounds/solutions?


When you have a single camera not drawing the entire screen, the unused areas are undefined. What’s actually drawn there varies depending on OS, drivers, graphics card, etc. It happens that the Unity editor seems to fill the undefined areas with black, but obviously this is limited to the editor only and can’t be relied on. So the solution is to not have any undefined areas, and always draw the entire screen. You can use two cameras for this, where the second camera is under the first, and just draws black over the entire screen. See here.