Search Unity

TextMesh Pro Resize Text Rect to fit text

Discussion in 'UGUI & TextMesh Pro' started by andyz, Mar 29, 2019.

  1. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,269
    Since I am adding items to a scroll list I want them to be as long as required so is there no built in option to make the RectTransform of a Text Mesh Pro UGUI label increase in height as required to fit the text within?
    i.e. no overflow, no truncation, just enlarge area!

    Edit: OK you can add a Content Size Fitter component but it complains about being in a layout group - a common Unity UI problem
     
    Last edited: Mar 29, 2019
  2. Vivien_Lynn

    Vivien_Lynn

    Joined:
    May 17, 2019
    Posts:
    19
    I am not exactly sure what you want to achieve, but this tutorial could get you on the right track.
    If you want to follow this tutorial, make sure to tick both boxes for "Control Child Size" (@1:38).

     
    Tazoru, ujz, Nanita and 6 others like this.
  3. Vivraan

    Vivraan

    Joined:
    Feb 2, 2018
    Posts:
    26
    This is not working in 2020.3.20f1 as of the timestamp of my post.
     
  4. Vivien_Lynn

    Vivien_Lynn

    Joined:
    May 17, 2019
    Posts:
    19
    I used this tutorial multiple times already. Just make sure to also tick both boxes for "Control Child Size" @1:38. That should be all that you need to take care of, to have everything working like shown in the video.
     
    Last edited: Nov 10, 2022
    Nanita likes this.
  5. CaypoH23

    CaypoH23

    Joined:
    Jan 5, 2020
    Posts:
    2
    @Vivien_Lynn , It works with TextMeshPro as well. Thank you!
     
    Last edited: Nov 29, 2021
    ujz and Nanita like this.
  6. RambosRide

    RambosRide

    Joined:
    Nov 8, 2020
    Posts:
    41
    upload_2022-10-13_8-59-4.png

    2021.3.4 - not working?
     
  7. RambosRide

    RambosRide

    Joined:
    Nov 8, 2020
    Posts:
    41
    In newer versions of Unity need to check "Control Child Size" width and height

    upload_2022-10-13_9-50-29.png
     
    estzafmag, mdimov and Nanita like this.
  8. Super-robot14

    Super-robot14

    Joined:
    Mar 27, 2023
    Posts:
    1
    This works so well! I have been searching for this and this is the only thing that has worked. I am using it on a Scroll Rect, and I am using code to change what the text says, I personally have to set the min height really high, as it's acting more as somewhat of a max height. Idk if it said that, or I was just bad and missed it, but this worked very well for me.
     
    Nanita likes this.
  9. Tazoru

    Tazoru

    Joined:
    Dec 31, 2018
    Posts:
    3
    Still works like a charm :)