Search Unity

TextMesh Pro Sudden TextMeshPro weirdness (component resetting, display issues)

Discussion in 'UGUI & TextMesh Pro' started by Democide, Mar 6, 2019.

  1. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    315
    So, I've been using TextMeshPro for a long time and have never had a similar issue. Now, recently some strange errors have started to show up.

    So, I have a prefab of a card. I instantiate a number of those for the different cards in the hand. Each of these prefabs has a few TextMeshPro components, for name, cost and card description. Now after the card was spawned I put the description into the text. This has always displayed fine but now it seems to cause some display errors. Some random cards (it doesn't seem specific ones) have display errors.

    At first these display errors were a very wide single-line text. I had it happen in the editor and noticed that the RectTransform component of this card's description had wrong dimensions, and that the TextMeshPro seemed to have its settings reverted (no wrapping etc.).

    Here's an example of what it looks like initially:

    textmeshpro-bug_1.png
    Notice the text on the highlighted card not breaking, being a larger size and super-wide.
    Also note that the text is wrong. It is just the card description without the keyword text in front. It should read: "Frappé Eclair. Furie: Inflige..."

    The code for this was:

    Card Visuals
    Code (CSharp):
    1. public void UpdateDescription() {
    2.     description.text = card.GetDescription();
    3. }
    Card Description
    Code (CSharp):
    1.  
    2.         public override string GetDescription(int damageModifier = 0) {
    3.             if (string.IsNullOrEmpty(description)) {
    4.                 return GetKeywordDescription();
    5.             }
    6.             else {
    7.                 return GetKeywordDescription(true) + Sharklib.Localization.Localizer.Get(description);
    8.             }
    9.         }
    10.  
    11.         string GetKeywordDescription(bool addEndSeparator = false) {
    12.             if (keywords == 0)
    13.                 return null;
    14.  
    15.             const string keywordSeparator = ". ";
    16.             var values = (Keywords[])System.Enum.GetValues(typeof(Keywords));
    17.             var stringBuilder = new System.Text.StringBuilder();
    18.             bool atleastOne = false;
    19.  
    20.             for (int i = 0; i < values.Length; i++) {
    21.                 if (keywords.HasFlag(values[i])) {
    22.                     if (atleastOne) {
    23.                         stringBuilder.Append(keywordSeparator);
    24.                         addEndSeparator = true;
    25.                     }
    26.  
    27.                     stringBuilder.Append(LocaStrings.GetKeyword(values[i]));
    28.                     atleastOne = true;
    29.                 }
    30.             }
    31.  
    32.             if (addEndSeparator) {
    33.                 stringBuilder.Append(keywordSeparator);
    34.             }
    35.  
    36.             return stringBuilder.ToString();
    37.         }
    38.  
    Note that I have recently added the Keyword description and this seems to have caused the error - I have had no occurences of it before that change but I don't see how it would trigger it.

    Anyway, now I have changed the code a bit and I get a similarly rare and random error, but it looks different. UpdateDescription() uses description.SetText(string) instead of description.text = string. And GetKeywordDescription() returns an empty string ("") instead of null if there is no text (since null causes errors with SetText).

    Now with that the visuals look like this:

    textmeshpro-bug_2.png
    Notice the blurryness of the highlighted card.
    Also the text is wrong. The text for this card should be nothing. I assume this is the text for the last card using this prefab (they are being reused)

    I have no way of reliably reproducing this issue and I am honestly stumped. Any help would be appreciated

    (Unity 2018.2.21, TextMeshPro Package is 1.2.4)
    (also, this is a repost from the digitalnative forum since I saw the post about moving support to the unity forum http://digitalnativestudios.com/forum/index.php?topic=1864.0)
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The blurriness is most likely an SDF Scale issue. Make sure the scale of the text object is uniform for (x, y, z).

    In regards, to the word wrapping and other issue, the easiest way for me to figure out what might be the cause is if you could submit a bug report with the included project or some simple Repro project. If you do submit a bug report, please let me know what the Case # is.
     
  3. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    315
    The scale of the description gameObject is never being affected directly, and as you can see in all the other cards works perfectly. I have fiddled with it a bit and one of the causes seems to be setting the text to null or "" while the gameObject is deactivated? I'm guessing that because the second type of error seems to only happen for cards with no text.

    In any case, reproducing this is hard but I can see - once I have some time - if I can set up a simple repro project.

    I'm mostly concerned about a) the text not updating and b) the rectTransform / TextMeshPro component settings somehow reverting.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The rendering weirdness on the Initiate card looks like an SDF Scale issue. When that card comes to the forefront, make sure it's scale is uniform for x, y and z.

    Just for testing and using a backup of your project, see if you get the same behavior using the latest release of TMP which is version 1.4.0-preview.3a for Unity 2018.3.
     
  5. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    315
    Will do!

    As a sidenote: The blurred text is also blurred when the card is small (at 1,1,1 scale). I have now set the description GameObject as inactive when I have no text (instead of temp.SetText("") or tmp.text = null) and have't seen the issue reappear - yet.