In my 2D project, I have a cinemachine setup with a pixel perfect camera. This camera is set to “Windowbox” mode, as this gives me the desired results of creating black bars on the top/bottom and left/right of the screen if the user resizes the main game window. This works perfectly.
However, the UI is a different story. I want my UI to stick to the game view only, and not go beyond the game view and into the black bars. To solve this problem, I decided to add a second camera that only renders the UI. On my main camera, I have this second camera in the stack as an “overlay” camera.
This does seem to work, but with a drawback I was not expecting. When the user resizes the game window, the UI will squash or stretch, depending on how the user resized that window. Obviously, this is unwanted behavior, so I was wondering how I could solve this problem.
I tried rendering everything with one camera, and setting my canvas to “screen space - overlay”, which also… works, but with unwanted behavior, as well.
Doing it this way gives me pixel shifting on the UI elements. Here’s a preview of that -
If I could get rid of this pixel shifting, this way of doing it (using one camera) would be ideal. However, rendering the UI to a second camera seems like a better approach. I just need to get rid of the squash and stretch during a game window resize.
Here are my canvas settings when using the second camera to render the UI -
Is there any way to get rid of this squash/stretch when using a separate camera set to overlay, or perhaps get rid of the pixel shifting when using one camera that has the pixel perfect component?