- Home /
Can I configure a Rect Transform to preserve its aspect ratio while stretching?
I'm working with the Unity 4.6 beta GUI, and trying to build my GUI in a way that will adjust to different resolutions/window sizes.
I have one object in my GUI that is designed to take up most of the available view, so it has to stretch as the resolution changes. However, it's also important that it maintain its aspect ratio.
I can cause the object to stretch with its parent canvas by placing its anchors at the corners of the object. I can cause the image component of the object to preserve its aspect ratio during scaling by checking the "Preserve Aspect" box on the component. But I need the entire game object to preserve its aspect ratio, not just the image. (There are child objects that need to remain aligned with the image.)
If I move all of the anchors to one corner of the object, then the object preserves its aspect ratio, but it also preserves its size, which causes it to appear small on high resolutions and/or get cut off on lower resolutions and wider aspect ratios.
Is there any way to configure the rect transform so that the entire game object will stretch based on its parent's size, but still preserve its aspect ratio?
Answer by troien · Nov 14, 2014 at 09:03 AM
There should be a component named AspectRatioFitter. Which can be used for just that.
(Unity 4.6.0b20)
Your answer
![](https://koobas.hobune.stream/wayback/20220613171438im_/https://answers.unity.com/themes/thub/images/avi.jpg)