Fixed aspect ratio with black bars

Hello,

I’m currently trying to enforce a 16:9 aspect ratio for our game and display black bars in case the screen does not match the ratio. All in-game objects are displayed correctly by setting the camera’s rect accordingly (I use this approach: unity - How to force keep the aspect ratio and specific resolution without stretching the output screen view? - Game Development Stack Exchange).

How do I have to adjust the UI Toolkit UI for not displaying anything on these black bars?

Initially, I thought that setting Scale Mode to “Scale with Screen Size” (parameters: Shrink, 1920 x 1080) would do the trick, but it does not work.

Can somebody help me with this issue?

I think this other post can help: How to have a VisualElement locked to aspect ratio?

1 Like