Search Unity

Bug Issues Using Fonts in UI Builder/UI Toolkit

Discussion in 'UI Toolkit' started by cb0d, Aug 20, 2022.

  1. cb0d

    cb0d

    Joined:
    Mar 18, 2022
    Posts:
    20
    I am trying to use an imported font within UI Builder, I've tried both .ttf and .otf fonts which are placed in /Assets/Fonts. After placing the font file into the Assets folder, it seems that I need to right-click > "Create" > "Text" > "Text Asset" in order to use the font within UI Builder. Otherwise applying the font doesn't work.

    Using the font asset which was created, I am able to apply the font to element within UI Builder. However, if I close the Unity Editor and reopen I will see the following errors:

    Unexpected recursive transfer of scripted class. 'BuilderDocument' is being transferred while trying to transfer 'ANGELIKAPLAYFULL-2OG5L SDF'
    UnityEditor.EditorJsonUtility:FromJsonOverwrite (string,object)


    UnityException: LoadFontFace_With_Size_and_FaceIndex_FromFont_Internal can only be called from the main thread.
    Constructors and field initializers will be executed from the loading thread when loading a scene.
    Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
    UnityEngine.TextCore.LowLevel.FontEngine.LoadFontFace (UnityEngine.Font font, System.Int32 pointSize, System.Int32 faceIndex) (at <646e907b5d0f4896b0001f3ab326ff3e>:0)


    The UI elements which were configured to use the new font will no longer show any text whatsoever.
    Unless I'm missing some crucial information about how to use fonts within UI Builder, this seems like some kind of bug. Any ideas?

    Unity Editor version 2021.3.6f1
     
  2. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    499
    Hi @cb0d!

    Fonts should work in the UI Builder, but they are no longer the recommended way. We don't have a lot of documentation on the subject, but I have answered a similar question in this thread if you want to look.

    As for the errors you are seeing this definitely looks like a bug to me. Can you log a bug through the Unity Bug reporter ?

    In the meantime, could you try with a different source Font to see if the issue is unique to the other Font ?

    Thanks again for bringing this up!
     
    cb0d likes this.
  3. cb0d

    cb0d

    Joined:
    Mar 18, 2022
    Posts:
    20
    I just realized that I replied to you in the wrong thread... Posting here as well for reference:

    /*****************************************************************************************/

    Hi! Thank you for the clarification. I went ahead and created a new blank project and reproduced the issues reliably with multiple different fonts files (.ttf and .otf). I also submitted a bug report with all the necessary information: CASE IN-14580

    Noted on the transition to the TextCore engine. It seems that it is recommended to create a Font Asset and use that within UI Builder, but can you clarify whether we should be creating a Font Asset via the "Text" or "TextMeshPro" system? Thanks.
     
  4. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    499
    No worries, I just answered in the other thread :)
     
  5. bottledgalaxy

    bottledgalaxy

    Joined:
    Jul 19, 2019
    Posts:
    85
    I'm having this same issue... has a bug been reported and if so what's the status? I tried looking for IN-14580 in the issue tracker but had no results

    Thanks!