Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Layout group not adjusting to preserve aspect/aspect ratio fitter

Discussion in 'UGUI & TextMesh Pro' started by Shack_Man, Feb 7, 2023.

  1. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    373
    Here I have 2 images that use 'preserve aspect' and a text element, grouped under a horizontal layout group. I use control child size and force expand so they fill out the entire space.

    upload_2023-2-7_14-5-13.png



    What I'm trying to achieve:

    1. The 2 images that use preserve aspect will close the empty space that was created, and the text (red) fills it up.
    2. Still use force expand so the layout group elements always fill up the entire space of the parent. Aka a responsive UI.

    I'm aware that preserving aspect doesn't change anything about the rect transform. I could use an aspect ratio fitter on the images, but the layout group still doesn't care about it:

    upload_2023-2-7_14-14-50.png


    upload_2023-2-7_14-17-1.png


    Here I have achieved this effect by removing the aspect ratio fitter and unchecking 'preserve aspect', but instead manually scaled the images rect transforms to keep the aspect. To fill up the space I enabled 'use child scale' on the layout group.

    Do I have to write and use a custom script that preserves an images aspect by scaling it? Or is there a simpler solution here?

    Thank you!