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

Question TextMeshPro text doesn't fit the full area, only auto size in fixed increments

Discussion in 'UGUI & TextMesh Pro' started by Epiplon, Jun 20, 2023.

  1. Epiplon

    Epiplon

    Joined:
    Jun 17, 2013
    Posts:
    49
    I set the text to Auto Size but it doesn't scale dynamically inside the box and I need it to scale until it doesn't fit anymore. I have a long list of words and some of them are appearing really small on the screen because of that.
    Besides, it's weird that whenever I move the area the font size only increases in steps of 0.05. Is there a way to change this?

    Unity_piqVXLo7cq.gif
     
  2. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,000
    Looking through the source code ( Scripts\Runtime\TMPro_Private.cs ) appears to have hardcoded minimum size delta of 0.05 throughout the autosize functions. That would explain why you are seeing steps limited to 0.05 increments.

    You could embed the TextMeshPro package and then alter those values, but be warned, even on a quick glance I saw half a dozen uses of that value, so you'll likely need to update many lines and ideally you should switch to using a field/property instead of the hardcoded value. Additionally you would now be locked into that version of TMPro, if you wanted to update to a newer version you'd have to embed the new version and then copy your changes over. Worse still come unity 2023 TMPro package is being moved into the UGUI package and so that would have to be embedded instead ... and yeah it gets nasty quickly.

    There might be an alternative though, as i'm puzzled as to why you your font size is so small!

    Normally small fonts are in the region of 8-9 pts, having that text be at maximum sub 0.5 pt suggests to me that something is not right. Somewhere you must be using a very small canvas, perhaps its in worldspace? In which case i'd first be looking to see if you can scale everything up and get back to using sane font size ranges. For example if the default size of the font was 10 pts, then being locked to steps of 0.05 would not be an issue as it should have plenty of resolution to scale smoothly to fill the space.
     
  3. Epiplon

    Epiplon

    Joined:
    Jun 17, 2013
    Posts:
    49
    Yeah, since I'm trying to fit these texts in the position of hexagonal tiles they have to be in Worldspace for a couple of reasons: panning and zooming in/out.

    I found somewhat of a hack: I increased the width and height area of the text by 10 and scaled the component down by 10. It's an ugly solution, as there doesn't seem to have any logical reason why that 0.05 is hardcoded and I don't wanna mess with the source package as we don't know what the potential issues it might create by changing this value. But now the text can fit the area much more accurately and it solves the issue I was having.