In my game the UI scales perfectly and fits the screen for all tested resolutions. No problem there.
But I need a background image for the UI that fills both width and height. Fitting an image to the UI Canvas
works fine, but squishes or stretches the image to fit different resolutions. Setting Preserve Aspect
fits correctly across the width but leaves blank bars top and bottom if the screen is too tall.
I cannot find any combo that fills on both windowed and full screen resolutions without stretching or squishing the image to fit. Well, there is one way which to make the image enormous, but that seems the wrong answer and all the image details get lost.
Thanks for adding some nice screenshots to the answer I already gave back in July last year.
– RaisedDude, thank you so much for posting this. It's so non-intuitive in Unity and I was pulling my hair out!
– NarrowsEchoing what karmington said: in my experience the "Aspect Ratio" must be the aspect ratio of the original image for the "Envelope Parent" and "Fit in Parent" modes to work intuitively. For example, a 16:9 image should have a 1.777778 Aspect Ratio. Setting Aspect Ratio to 0.001 in Envelope Parent mode instead forces a "Fit To Width" behavior.
– PrimordialAmazing aproach. I work with UI in unity for a long time, and have always used workarounds for this situation! Thank you!
– RhombWorks like a charm, thank you! Also, if anyone else comes across this, you can actually write the aspect ratio directly, like "16/9", and Unity will calculate the resulting value correctly. All basic math operations work in any inspector number field.
– Atween