How can I ensure pixel-perfect scaling between UI buttons and game objects in Unity?

I’m working on a pixel art game in Unity, and I want to make sure that my UI buttons and game objects are scaled proportionally to each other according to pixel perfection principles. But when I set the same scale for both button and object they are not aligned correctly based on pixel ratio. How can I make sure that both my UI elements and game objects maintain a consistent pixel ratio across different screen resolutions?

1 Like

I would start with some pixel perfect tutorials, and also pay attention to anchoring and scaling in the UI.

Here are the official docs on how to make your UI handle various resolutions and aspect ratios cleanly:

Here are some notes on UI Anchoring, Scaling, CanvasScaler, etc:

Usually you need to choose a suitable ScaleMode and MatchMode in the Canvas Scaler and stick with it 100%. Generally if you change those settings you will often need to redo your UI entirely.

Here’s some more fit-inside-UI-content notes:

https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/HOWTO-UIFitContentSize.html

I also use this CanvasScalerOrientationDriver utility to make sharing UI for Landscape / Portrait easier. Read what it does carefully.

Pixel Perfect requirements are extremely stringent, like a banknote:

1 Like