Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    372
    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!