Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Possible to revert to 2018 TextGenerator settings in 2019?

Discussion in 'UGUI & TextMesh Pro' started by Percy-Pea, Oct 1, 2019.

  1. Percy-Pea

    Percy-Pea

    Joined:
    Aug 31, 2014
    Posts:
    75
    It looks as if Unity 2019 no longer stores verts for spaces and new lines etc in a text field.

    For example, in Unity 2018, a basic UI Text field with
    New Text
    New Text

    Would report 72 verts when logging GetComponent<Text>().cachedTextGenerator.verts.Count

    In 2019, it reports 56 verts.


    In fairness, 2019 works better as you'd expect there to be just 56 verts with just 14 letters (4 verts per character).

    However, some code we use, relies on there being a quad for each character in the text, which does include the spaces and new lines. Is there a way to set the textGenerator settings in 2019 to do as 2018 did?

    As a side, note I can't see anything in Unity 2019 release notes mentioning this change?
     
  2. Percy-Pea

    Percy-Pea

    Joined:
    Aug 31, 2014
    Posts:
    75
    Sneak bump.
     
  3. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Simple answer is no there is no way to revert it. It was done as a bug fix and is more correct behavior.
     
  4. Percy-Pea

    Percy-Pea

    Joined:
    Aug 31, 2014
    Posts:
    75
    Ah, yes I agree it's a more correct behaviour, but sadly has been a headache to solve.

    Before for example, if you had two lines in a text field and wanted to scale the verts of the first character in the second line. You could find the index of the first of those 4 verts by simply doing :-

    Text.cachedTextGenerator.lines[1].startCharIdx * 4;

    Lets say the text was :-
    Line 1
    Line 2

    In pre Unity 2019 it was nice and easy to find the verts for the 'L' in Line 2 and do something with them.

    Now, looking up the vert index using startCharIdx on the UILineInfo will give you the verts for the 'n' in Line 2.

    :(

    Is possibly the issue that there is now a bug with the startCharIdx still including spaces/newlines etc?
     
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Any reason why you are still using UI Text instead of TextMesh Pro?

    TMP does provide more information over the resulting text in terms of identifying characters, words, lines, links, etc. and reference to their underlying geometry. Once a text object has been rendered, the TMP_Text.textInfo class is populated with all this data to be queried for all kinds of uses.
     
  6. Percy-Pea

    Percy-Pea

    Joined:
    Aug 31, 2014
    Posts:
    75
    Alas the reason is unknown to me. It's part of a project I've taken over rather than created from scratch. TMP would have been my preferred choice :)
     
  7. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    I guess there could be a bug with that yes.

    Also note that it didnt just remove white spaces any rich text tags would generate verts as well. so a tag like "<color=red>" would generate 44 verts (11 *4) not so bad when its small but quickly becomes a large overhead when it get longer

    .