Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity UI Content size fitter inside vertical layout group

Discussion in 'UGUI & TextMesh Pro' started by Afropenguinn, Sep 9, 2017.

  1. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    305
    I have a scroll rect that contains a vertical layout group which contains multiple text elements. This works fine when each text element has a predefined height, but what I'd like to do is put a content size fitter on them so that they will expand their height to fit the text inside them. Unity doesn't seem to like this though, as it puts a warning on the content size fitter, and the scene can be infinity saved with it still complaining it hasn't been saved. The UI elements also seem to jump around occasionally, even in the editor view. Is there any way to properly accomplish this?
     
    unity_uCAh1YGgjxXPOw likes this.
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    This has confused me a lot in the past, and continues to do so sometimes still...

    I tried a simple setup like yours, without knowing your exact design.
    Scroll View -> content (has vertical layout)(could also have content size fitter) -> Text (n number of elements)

    The vertical layout has : Child Controls size : width + height.
    The text elements have a 'layout element' and all i set was "flexible width = 1'

    I'm not a pro at the layout fitting, but if this helps you..great :)
     
    MafiaMoe, nirvanajie and Afropenguinn like this.
  3. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    305
    Yep, that was the solution, thanks!
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Cool, glad it worked for ya :)
     
  5. PuzzledBoy

    PuzzledBoy

    Joined:
    Sep 9, 2014
    Posts:
    23
    wow, that save me a day, thank you.