- Home /
Is there a way to get Image>Preserve Aspect to work with children?
On my canvas I have an Image with Preserve Aspect ☑. Even with anchors in same location as the bounding Rect they won't scale properly in some aspects. Aspect ratio fitter attached to the children does not seem to help. Is there any way to get preserve aspect to work well with its children?
Answer by AbandonedCrypt · Feb 12, 2021 at 08:48 AM
I don't know if your issue really lies there and I am not sure if there are built-in ways to do this, but at last you could do something as simple as attaching a script to the parent and put this in the start method:
for(int i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).GetComponent<Image>()?.preserveAspect = true;
}
(I am writing this in browser, since I am at work, so take this as pseudocode)
Thanks for the suggestion but it doesn't seem to work. If you have Both a parent and a child with preserveAspect to true, they still won't scale as if they are part of the same image. At least not if the image gets to wide or narrow. I'm fairly certain there isn't a built-in way to do this as preserving the aspect ratio can ignore the anchors which the child depends on (I think).
Did you try setting the child to "Stretch" in the anchor window? Otherwise I feel like your description of what you are trying to achieve is not very clear.
I'm trying to make is so that this Doesn't become this
Sorry for any confusion.
Your answer
![](https://koobas.hobune.stream/wayback/20220613025031im_/https://answers.unity.com/themes/thub/images/avi.jpg)