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
  3. Dismiss Notice

(Answered myself) Fitting content until parent size has been reached

Discussion in 'UGUI & TextMesh Pro' started by MaskedMouse, May 5, 2020.

  1. MaskedMouse


    Jul 8, 2014
    One of the major struggles with setting up UI is that when you have a content size fitter, it grows unlimited wide / heigh.

    Is there a way to actually let the UI object grow with the content size fitter until it has reached the size of the parent?

    so let's say the Parent (Container) has 700 width x 300 height.
    The Panel child has a content size fitter with a vertical layout group.
    A text element as child of Panel.

    Container -> Maximum size
    - Panel -> dynamic sized
    -- Text

    How to achieve this? as it seems I can only give a preferred width and height which will automatically expand the panel to that value, instead of growing as the content grows.
    I need to contain the growth to a maximum.

    And suddenly I fiddled enough to get it done.
    Container is now vertical with a content size fitter set to preferred. With 720x360
    Container only the rect
    Panel now has a vertical group with just some padding
    Text element has a layout element containing a minimum height and width

    And it seems to be contained within the box as it expands.
    It is quite a horror to juggle around with these components to actually get the result you want
    Last edited: May 5, 2020