Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Content Size Fitter + Wrap Text problems

Discussion in 'UGUI & TextMesh Pro' started by B2F, Mar 22, 2017.

  1. B2F

    B2F

    Joined:
    Jul 10, 2013
    Posts:
    23
    So I'm making a tool tip that will have text that is dynamically added. Right now I have the following set up:

    Parent:
    Rect Transform - Width = 200
    Content Size Fitter - Horiz Fit = Unconstrained & Vert Fit = Preferred Size
    Horizontal Layout Group - Force Expand = false & Child Control Size = true

    Child Text
    Text Component - Horiz Overflow = Wrap

    This works as intended as far as if I press the enter key the parent expands vertically to fit the new line of text, however if I create a new line from the text wrapping (rather than pressing enter) the parent does not expand vertically to fit the new line of text.

    Also I noticed that when text is wrapped the preferred height of the text layout component remains unchanged.

    Any ideas on how I can get the parent to expand vertically to fit the new lines of wrapped text?

    I've looked all over but I can't seem to find a solution to this. Thanks in advance for your help!
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,273
    seems to work here with wrap or with enter (tested on unity 5.5.2p1)

    canvas-wrap.gif
     
  3. B2F

    B2F

    Joined:
    Jul 10, 2013
    Posts:
    23
    Am I doing something wrong or is this a bug in Unity 5.5.0x1 Collab?

     
    Savidiy and guetta18 like this.
  4. Akfly

    Akfly

    Joined:
    Jan 31, 2017
    Posts:
    12
    This is how I achived this, I hope it might be of some help :p

    PARENT
    Vertical Layout Group:
    • Child alignment - Upper Left
    • Child Control Size - [x] Width - [ ] Height
    • Child Force Expand - [x] Width - [ ] Height
    • (You should add some padding too)
    Content Size Fitter:
    • Horizontal - Unconstrained
    • Vertical - Preferred
    CHILD TEXT
    Text:
    • Horizontal Overflow: Wrap
    • Vertical Overflow: Truncate
    Content Size Fitter (This gives a warning, but it's ok, since the parent Layout group only restrains horizontal axis, and here we restrain the vertical axis)
    • Horizontal - Unconstrained
    • Vertical - Preferred Size
     
  5. B2F

    B2F

    Joined:
    Jul 10, 2013
    Posts:
    23
    Thanks for the reply! However, I get the same behavior as I did previously in the OP with this set up.
     
    Last edited: Mar 22, 2017
  6. Akfly

    Akfly

    Joined:
    Jan 31, 2017
    Posts:
    12
    Mmm... When you set the Vertical Overflow to Truncate, does your text keep drawing outside the boundaries or it disappears? I'm asking this because I can't see the lines delimiting your Text in your gif, so I think that the problem might be that your Text is not resizing.

    I also think that this may be a bug with your version, since I tested it on 5.5.0p1 and 5.4.2p3; and @mgear tested it on 5.5.2p1 :/
     
  7. B2F

    B2F

    Joined:
    Jul 10, 2013
    Posts:
    23
    Yes that is accurate. My text is not resizing as it should. I guess its just a bug in my version? I'll send over a bug report. Thanks for the help guys!
     
  8. B2F

    B2F

    Joined:
    Jul 10, 2013
    Posts:
    23
    I confirmed with Unity staff that this is a bug in the version I'm using right now and is fixed in later versions.
     
    SimonDarksideJ likes this.
  9. unity_sTKXHclFXh5sEA

    unity_sTKXHclFXh5sEA

    Joined:
    Nov 23, 2017
    Posts:
    3
    Still a bug or undesirable feature in 2017.4.0f
     
  10. guetta18

    guetta18

    Joined:
    Jul 24, 2018
    Posts:
    19
    works for me! :)
    ezgif-5-c74abe49454a.gif
     
  11. jakesee

    jakesee

    Joined:
    Jan 7, 2020
    Posts:
    59
    THIS is the real deal! Yes, we can and need to ignore the warning if the layout groups in the parent does not impose layout constraints in the axis we want to auto size. Thanks!