Search Unity

Aspect Ratio Fitter and groups

Discussion in 'UGUI & TextMesh Pro' started by Melang, Oct 2, 2014.

  1. Melang

    Melang

    Joined:
    Mar 30, 2014
    Posts:
    166
    What I want to do: just a Horizontal Group that retains the aspect ratios of its children. It should still be possible to control spacing and alignment, just like in a regular Horizontal Group.

    I'm fine with either a built-in way or coding a workaround, as long at it's not superhacky. Please point me in the right direction.

    What I tried: aspectfitter1.png aspect2.png aspectfitter3.png
     
    Exeneva and lelouch120 like this.
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    If you're using an AspectRatioFitter on the child of a layout group, you should see a warning in the Inspector of the AspectRatioFitter saying basically "Don't do that!" because it's not supported.

    However, you should be able to use an AspectRatioFitter on the child of the child of the layout group and set it to fit in parent. I didn't understand your desired outcome completely, so not sure if this will work for you.
     
  3. Melang

    Melang

    Joined:
    Mar 30, 2014
    Posts:
    166
    I'll try to better explain what I need. I have a button with text and image children, their anchors are set to their own corners, so they scale nicely and keep their aspect ratio when the parent is scaled: ribbon1.png
    This is how a Horizontal group behaves with Expand height checked and keep aspect ratio checked on the button - this behavior is exactly what I need:
    ribbon2.png
    However, in the example above the button didn't have any child objects. When I try to do the same with the button that has child objects, here's what it looks like:
    ribbon3.png

    I just want to find a way to have the regular Horizontal Group behavior apply to the button with child objects.
     
    Exeneva and lelouch120 like this.
  4. Melang

    Melang

    Joined:
    Mar 30, 2014
    Posts:
    166
    Actually, even the "good" example without the child objects on the button has a problem - the clickable area doesn't correspond to the button image there. This issue is probably more important than my 'child elements" issue.
     
    Exeneva likes this.
  5. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Try the approach I suggested before: Instead of putting the image on the child of the layout group, put them on the child of the child, and add as AspectRatioFitter component to that.
    • LayoutGroup
      • Child (no components except RectTransform)
        • Child (AspectRatioFitter and Image components here)
     
    ow3n, WhiteGfx and Melang like this.
  6. Melang

    Melang

    Joined:
    Mar 30, 2014
    Posts:
    166
    Thanks a lot, it totally worked!

    ribbonfinal.png
     
  7. MaxEden

    MaxEden

    Joined:
    Jun 22, 2013
    Posts:
    82
    God, that's the cutest anchoring I've ever seen...
     
  8. akuadalahnamaku

    akuadalahnamaku

    Joined:
    Dec 21, 2022
    Posts:
    4
    cant seem to work for me, when i resize the group the text doesnt auto resize