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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

TMP with fallback fonts doesn't show correctly, because of... layout, or size fitter?

Discussion in 'UGUI & TextMesh Pro' started by OdedEisenPixi, Mar 15, 2020.

  1. OdedEisenPixi

    OdedEisenPixi

    Joined:
    Aug 27, 2019
    Posts:
    7
    Hi @Stephan_B,
    we are using calibri font for our chat, and noto CJK as fallback fonts (dynamic, mostly).
    The only issue is with chat:
    This is how it looks like

    (when the font is calibri and the noto CJK as fallback)
    but if I put the noto CJK in the prefab, it looks how it should be:

    the chat bubble size is changed on creation (with layout group and content size fitter at it's parents)
    Any idea\suggestion on how to solve this? (I can't change the font asset of the prefab at runtime because of other localization reasons).
    I also tried to ForceMeshUpdate, but to no avail
     

    Attached Files:

  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    The issue is most likely related to these fonts having very different metrics and more specifically Ascent and Descent lines as you can see in the image below.

    upload_2020-3-15_12-16-14.png

    As you can see in this image, the Ascent Line of NotoSans CJK is significantly taller than Calibri where depending on which font asset is assigned as the primary would impact the layout for a variety of reasons. Without going over all these potential reasons, the easiest solution would be to normalize the face metrics of these two very different font asset to make sure they blend in nicely with each other.

    To normalize the face metrics of these two font assets simply adjust their Ascent and Descent line in the Font Asset Inspector as seen below. To visualize these metrics, add the TMP_TextInfoDebugTool.cs included in the TMP Examples & Extras to the text object and enable Show Characters.

    upload_2020-3-15_12-46-59.png

    As you can see above, I adjusted the Ascent and Descent Line of both Calibri and NotoSans CJK to match those of LiberationSans since (1) it might be used as fallback if it is still the default font asset assigned in the TMP Settings and (2) because this ends up being a happy medium between our two other font assets.

    BTW: I could have chosen to match the Ascent and Descent line of Calibri to NotoSans CJK but given the Cap Height (top of tallest capital letter) of Calibri is so much lower than NotoSans CJK, you would likely end up with too much space between lines when only using Calibri.

    There is no absolute right way of adjusting these metrics. In the end it comes down to adjusting these values to get a layout that looks good for your needs.

    So give this a shot and let me know if adjusting these metrics allows you to get the visual / layout results you seek?
     
  3. OdedEisenPixi

    OdedEisenPixi

    Joined:
    Aug 27, 2019
    Posts:
    7
    @Stephan_B
    Thank you for the in-depth response.
    I tried it, but it doesn't seems to be the problem. it looks like the ascend\descent lines are okay, but the letters are created/positioned in a different position of where they should be :/

    Also the answer doesn't explain why it works well in the rest of the game, and only in the chat works funny.
    Here's a link to a unity package that shows how it is built, and maybe from there you might be able to understand the source of the issue (the package is 17 mb because of the CJK font. Also add the dynamic fonts as fallback to see the behaviour)

    Thank you again :)
     

    Attached Files:

  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    The cause of the strange behavior is the result of the "MessageText" object in your prefab having another text object child "MessageDate" which happens to also have a child SubMesh object as seen below.

    upload_2020-3-16_16-4-44.png

    As such, when the main text object "MessageText" looks for a sub mesh object for the fallback, it finds this sub child object which that is a child of MessageDate which is positioned relative to the MessageDate so the glyphs coming from the fallback end up offset.

    SubMesh objects are no longer serialized but most likely this prefab was created with a previous version when they were still being serialized.

    Deleting this TMP SubMeshUI object from the text objects in this prefab and other prefabs should resolve the issue. Below is the edited prefab without those sub mesh objects.

    upload_2020-3-16_16-10-58.png

    Testing with the changes

    upload_2020-3-16_16-12-0.png


    I will further investigate this to see if I can catch the issue automatically but you should be good to move forward without any future changes.

    P.S. Since there is no way to have the Prefab system ignore certain objects when updating or creating prefabs, make sure the default text doesn't use a fallback which would force the creation of a sub object.
     
    Last edited: Mar 17, 2020
  5. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Since the main cause of the issue you ran into is related to sub text objects getting saved with Prefabs, I made a change where sub text object will now have HideFlags.DontSave set to prevent them from being saved with the Prefab as they are created as needed anyway.

    This change will be in Preview 8 which should be out tomorrow if I stop making changes and don't run into any new issue.
     
  6. OdedEisenPixi

    OdedEisenPixi

    Joined:
    Aug 27, 2019
    Posts:
    7
    Works!
    Thank you very much :) :) :)
     
    Stephan_B likes this.