Search Unity

Official Feedback wanted : new text engine

Discussion in 'UI Toolkit' started by antoine-unity, Nov 17, 2020.

  1. darreney

    darreney

    Joined:
    Oct 9, 2018
    Posts:
    34
    Hi, may i know how to get outline working?
    this is what i have on my uxml file
    <ui:Label text="Settings" display-tooltip-when-elided="true" name="settings-text" style="-unity-text-align: upper-center; font-size: 30px; -unity-font-style: bold; -unity-text-outline-width: 5px; -unity-text-outline-color: red; color: rgb(160, 252, 255);" />

    but i do not see any outline either on the canvas or when i run the game.

    Does it have to be some special font that supports outline?
    Because from my understanding, in TMP outline is achieved through shader.
    Any help on getting an outline displayed will be appreciated!
     
  2. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    The only requirement should be that you need to reference a FontAsset as the font in your UI.
     
  3. darreney

    darreney

    Joined:
    Oct 9, 2018
    Posts:
    34
    Thanks for the reply!
    yes i've tried that too but still no luck.
    I've even did a simple script to set the outline in C#


    Label txt = rootElement.Q<Label>("settings-text");
    if (txt == null)
    {
    print("label not found");
    return;
    }
    else
    print("label found");
    txt.style.unityTextOutlineWidth = 10;
    txt.style.unityTextOutlineColor = Color.red;

    But still the same, no outline is observed.

    Is there a sample project that i can download to see the correct setup?
     
    Last edited: Mar 4, 2021
  4. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    From the Package Manager UI you can import the UI Toolkit Examples, and then in a new scene, hit the menu item "Window > UI Toolkit > Examples > Text". None of them demonstrate text shadow per say, but they would show the expected setup to get the new engine to work.
     
  5. darreney

    darreney

    Joined:
    Oct 9, 2018
    Posts:
    34
    ok i've made the following edit to the first item in the file Text_BasicStyleTags.uxml which is part of the UI Toolkit Sample.

    <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
    <ui:VisualElement class="background">
    <ui:Label text="Rich Text Tags" class="title" style="-unity-font: resource(&apos;Fonts &amp; Materials/Bangers&apos;); -unity-font-style: normal; font-size: 35px; -unity-text-outline-width: 5px; -unity-text-outline-color: red;" />

    But i am still not seeing any outline..
    Appreciate your advise on where i'm doing it wrong.. Or best if you can send me a link to a working outline sample. Thanks!
     

    Attached Files:

    Last edited: Mar 6, 2021
  6. Bet0v

    Bet0v

    Joined:
    May 23, 2015
    Posts:
    5
    Hi, it would be awesome to finally get a feature-rich native text system internally updated! Therefore I am interested in what you have to say @antoine-unity about what Anthony Blackett was putting forward. Do you plan to one day get rid of the actual outdated or weirdly updated systems at least when first installing a new project?
    About the "weirdly updated" I was for instance reffering to the fact that the main TextMeshPro developer seems to be working mainly alone, copying some of the Unity teams updates and integrating it to TMPro, which seems fine for an external Asset but very odd for an asset Unity owns.
     
    MrMahgu likes this.
  7. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Will the new text engine use unity sprite atlases? Text mesh pro sprites are good but it’d be nice to be able to have unity pack the atlases so sprites can be added and removed more easily.
     
  8. deep_deep

    deep_deep

    Joined:
    Aug 10, 2019
    Posts:
    16
    Can we use rich text in the editor, a.k.a. UIElements, without having to import any packages?
     
  9. marcospgp

    marcospgp

    Joined:
    Jun 11, 2018
    Posts:
    194
    Adding text shadow to a label should not require right clicking the font and creating a "font asset" (which I have no idea what it is for). There should be a progressive disclosure of complexity - and quite often Unity's UI tends to throw the entire arsenal of settings at us all at once. I wish the UI toolkit could start veering in a better direction.
     
    tonytopper likes this.
  10. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    499
    Hi @marcospgp , thanks for the feedback! You indeed shouldn't need to create a FontAsset in order to use TextShadow. This is fixed in 2021.2.0a14, and that will be fixed in the next release of the package (preview.15).

    Also, you are absolutely right in the sense that we are missing documentation on these new assets (FontAssets, PanelTextSettings...). This is something we will start tackling soon. In the meantime, there is a bit of existing documentation on these assets in the TextMesh Pro documentation that you could look at. Even though it is not the same system, it is still a good starting point on why those assets were added. https://learn.unity.com/tutorial/textmesh-pro-font-asset-creation#

    @deep_deep , rich text in the editor is now available in 2021.2.0a14.
     
  11. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Am I using this wrong or is it not supported? 2021.1.7 with UIToolkit and Builder preview14 installed.

    <ui:TextElement enable-rich-text="true" text="<Link>Testing</Link>" />

    Syntax - Xml is not valid, exception during parsing: System.Xml.XmlException: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 10, position 59.

    [edit] So it seems we must use &lt; and &gt; which is not nice, but fine.
    I can still not get any styles defined in the TextStyleSheet to actually show up though, only the ones listed in that google doc. (I'm making runtime UI , not Editor)



     
    Last edited: Jun 12, 2021
  12. dthurn

    dthurn

    Joined:
    Feb 17, 2015
    Posts:
    77
    Is the new text engine only capable of doing inner outlines? These look pretty bad on small fonts, an 'outer outline' is preferable (drawing the outline behind the characters, essentially)
     
  13. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    1,003
    Half of the outline will be inside, the other half outside. We don't have (yet) fine-grained controls over the outline offset, but we will consider exposing those. I'm pretty sure they are exposed for TextMesh Pro.
     
    Nexer8 and dthurn like this.
  14. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,276
    Hi I admit to not having used UIToolkit yet, but the major issue with all text in Unity has been it's tendency to not look great in 1080p or below (or non-4k) resolutions. The pixel snapping is not quite good enough - and compares poorly to other apps. I think there was/is a windowed mode UI issue with odd dimensions also - suddenly all text goes soft!!

    Are things any different with UIToolkit? Are bitmap fonts still the best way to get the sharpest text in this instance (which is not great if supporting a range of resolutions)?

    e.g. this screen grab is from the Unity hub - the verticals in particular are poorly pixel snapped in many cases.
    Native Windows apps get around this with sub-pixel smoothing (ClearType)
    text.png
     
  15. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

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

    Up to now, Unity has used TextNative for its default TextEngine. It used bitmap fonts, and it indeed had some blurriness issues when the text didn't align on the pixel grid. This post announces that UI Toolkit is now using TextCore as its default TextEngine. It's the same TextEngine as TextMeshPro, so it uses SDF. This comes with tremendous benefits such as the ability to render text at any point size, being sub-pixel accurate, many text effects, and much more. In addition, this TextEngine provides a lot of options to ensure a good rendering quality.

    As for the Unity hub, it is not using UI Toolkit nor TextCore to render text, so it is not a good example. You could test this new TextEngine by playing with labels and FontAssets in the UI Builder.

    I hope it helps!
     
    jiraphatK and Ruchir like this.
  16. PassivePicasso

    PassivePicasso

    Joined:
    Sep 17, 2012
    Posts:
    100
    Is it correct to assume that none of this will be back ported?
    I've build a Markdown renderer and editor for UI Elements which works fairly well, but its designed to be compatible with Unity 2018+
    The features made available by this rich text system seems like it would improve the performance during Geometry change events which is one of the biggest problems I'm facing, which is a result of the text being broken into a label per word to deal with layouting requirements

    It would be ideal if I didn't end up with two implementations I've been able to maintain compatibility between 2018 and 2021 without using TextCore/TextEngine but it would be nice to not build an entirely separate system on this new feature for newer versions of Unity to take advantage of this.
     
  17. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

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

    Indeed, unfortunately, this new TextEngine will not be backported as the changes required are too important.

    TextCore supports many rich text tags, as is shown in the first post of this thread. Also, using the new RichText support will be more performant than having one word per label as there is a cost associated with having more VisualElements. However, keep in mind that there are still a few limitations, such as the fact that there are no event callbacks for characters, words, and lines... Which the one word per label approach support.
     
  18. dujimache

    dujimache

    Joined:
    Dec 17, 2011
    Posts:
    89

    When will support rich text string for TextFields??? want to use <sprite>tag.
     
    Last edited: Jul 21, 2021
  19. april_4_short

    april_4_short

    Joined:
    Jul 19, 2021
    Posts:
    489
    Is there a product manager for game UI at Unity?

    Can we hear from this person?
     
  20. benoitd_unity

    benoitd_unity

    Unity Technologies

    Joined:
    Jan 2, 2018
    Posts:
    331
    Hello!
    The team is currently refactoring the TextField to also use TextCore instead of TextNative, which will enable rich text tags and fix many of the current quirks. This update should release in 2022.1, and we'll try to back port it to the 2021 LTS as well.
     
    Ruchir likes this.
  21. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    Will there be an API available to integrate custom tags into the system, say I wanna have a shake/Vibrate tag that i want to implement or any gameplay effects, how do I go about doing that?:)

    I really hope that this new text engine becomes a go-to solution instead of having to buy a custom text engine for just simple effects all the time.:(
     
  22. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    So that it's not (again) forgotten and ignored, posting about this here as well: moving to TextCore is all well and nice, but if the price is that you make everyone's eyes bleed on default 100% scale monitor resolutions I don't think that's right.

    Case 1336734 (Closed) [Regression] Font Rendering in the Editor is broken, again

    In a nutshell: on a 100% scaled screen, as basically every designer is using, text on 2021.2 (where many parts of the editor UI have been moved to TextCore), is blurry, hard to read, and somehow Unity is firm on saying that this is by design. All advances in font rendering at small resolutions, e.g. for professional tools, seem to be void here.

    There's an issue tracker link for the issue as well: https://issuetracker.unity3d.com/is...h-dull-text-rendering-in-the-inspector-window (incorrectly marked as "no regression", this is a regression)

    I can only encourage everyone to vote on this. Yes, some people care about readability, and no, not everyone will magically be on Retina screens overnight.
     
    Last edited: Jul 25, 2021
    Neto_Kokku and april_4_short like this.
  23. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    I think this is a valuable conversation to have but @april_4_short can you please start a new thread in the forums?

    Not only this would help more people voice their opinion on the matter as the title would indicate the topic, but we are also losing the spirit of that thread which is to specifically discuss new text features.
     
    MousePods and RunninglVlan like this.
  24. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
  25. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    Hi. I used UGUI for main UI and UI Toolkit for something experimental UI and debug UI. In this case, should I create and manage two types of font assets? Text>Font Asset and TextMeshPro > Font Asset.

    Is there any method that using unified font asset for both UGUI and UI Toolkit?
     
  26. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    499
    Hi @Kichang-Kim,

    Unfortunately, at the moment, text assets cannot be reused between TextMeshPro and TextCore. However, we are aware of the issue, and we are currently working on a solution to share the same assets between the 2 text systems.
     
    MousePods and Kichang-Kim like this.
  27. RunninglVlan

    RunninglVlan

    Joined:
    Nov 6, 2018
    Posts:
    182
    I tested and couldn't get
    <sprite name="spriteName">
    to work. Is it not supported yet?
    <sprite index=1>
    and
    <sprite="assetName" index=1>
    work, but
    <sprite="assetName" name="spriteName">
    doesn't work either.
     
    MousePods likes this.
  28. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    Can someone shed some light on it?:)
     
  29. RunninglVlan

    RunninglVlan

    Joined:
    Nov 6, 2018
    Posts:
    182
    Any ETA on when
    <sprite name="spriteName">
    will be supported?
     
    MousePods and Ruchir like this.
  30. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    I can honestly say I didnt have custom tags in mind but will defiantly bring it back to the dev team see if its something we can add.
    The Text system will be modular enough for generation where you will be able to modify the layout, parsing, and generation results. The final design on how this will work is still in progress but using one or all of the options you would be able apply a "shake" to the text.

    That being said if you have more example of tags you'd like to implement let us know a strong use case always helps decisions.
     
    Ruchir likes this.
  31. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    I will have to take a look at your specific example but not all tags supported just yet its on the list of things to correct though no current ETA.
     
  32. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    I think this asset should be a pretty good example for having custom tags:
    https://assetstore.unity.com/packages/tools/gui/text-animator-for-unity-158707
    https://assetstore.unity.com/packages/tools/gui/super-text-mesh-57995

    There are a few more on the Asset Store, but considering we can't really have another text system for UI elements as we could for game-object based UI system, it would really make a lot of gameplay effects really difficult to implement or seem hacked on top. it would also make it hard to ensure compatibility between multiple asset maybe offering different text effects on Asset Store (in future).

    The new overlay system is a good example as to how something built in to unity could streamline editor tools development and ensure compatibility between multiple tools. :)
     
    HugoBD-Unity likes this.
  33. FreddyC-Unity

    FreddyC-Unity

    Unity Technologies

    Joined:
    Jun 9, 2021
    Posts:
    36
    Hi @RunninglVlan,

    The name attribute tag is already supported. Could you verify whether the value provided in the name attribute matches with the name in the Sprite Character Table (.asset file)?
     

    Attached Files:

    RunninglVlan likes this.
  34. RunninglVlan

    RunninglVlan

    Joined:
    Nov 6, 2018
    Posts:
    182
    After checking one more time with the latest beta we can run (2021.2.0b8), yeah, name attribute works.
    Created UITK and TMP Sprite Assets from EmojiOne texture
    <sprite index=0>
    <sprite="UITK-EmojiOne" index=1>
    <sprite name="EmojiOne_2">
    <sprite="UITK-EmojiOne" name="EmojiOne_3">

    <sprite index=0>
    <sprite="TMP-EmojiOne" index=1>
    <sprite name="EmojiOne_2">
    <sprite="TMP-EmojiOne" name="EmojiOne_3">
    But I noticed that changing Scale of the Glyph Rect doesn't work.
    upload_2021-9-9_15-12-54.png
    BTW, will UITK Sprite Asset work the same as TMP Sprite Asset regarding updating Glyph Rects in real time instead of pressing Play Mode every time?
     
    Last edited: Sep 9, 2021
    HugoBD-Unity likes this.
  35. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

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

    This has been fixed in 22.1 and it is in the process of being backported to 21.2. In short, changes made in a text asset inspector (FontAsset, SpriteAsset...) should now be reflected automatically in the GameView and in the UI Builder. For other EditorWindows you'll need to make sure Live Reload is enabled on the window.

    I'll log a bug for this, thanks for bringing this up!
     

    Attached Files:

    RunninglVlan likes this.
  36. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    356
    Hi RunninglVlan,

    I am very curious how you got this to work? According to this thread, https://forum.unity.com/threads/sprite-asset-regression.1129589/#post-7441535, sprite asset it broken and the push hasn't been fixed yet. Are you on a developer build that the rest of us don't have yet? :)
     
  37. RunninglVlan

    RunninglVlan

    Joined:
    Nov 6, 2018
    Posts:
    182
    TomTheMan59 likes this.
  38. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I fixed the Sprite Glyph scale not working with UI Toolkit.

    It will take a few weeks for this fix to land. I will be backporting this fix to Unity 2021.2.
     
    RunninglVlan likes this.
  39. dthurn

    dthurn

    Joined:
    Feb 17, 2015
    Posts:
    77
    Any chance of getting support for TextMeshPro's automatic font resize functionality in UIToolkit? It's very useful and quite annoying to re-implement :)
     
  40. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    499
    Hi @dthurn,

    The "Auto-Size" feature from TextMeshPro has been requested many times, and it's something we'll add at some point. Unfortunately, there is no precise ETA on when we'll be able to tackle this yet.
     
  41. RunninglVlan

    RunninglVlan

    Joined:
    Nov 6, 2018
    Posts:
    182
    Cool, can we track the progress somewhere?
     
  42. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    499
    Since a user didn't log the bug, there is no public tracker. However, it should be in one of the subsequent 2021.2 releases as it is fixed in our internal staging branch.

    PS: I took a mental note to ask users to open bugs themselves for better tracking and visibility.
     

    Attached Files:

  43. dthurn

    dthurn

    Joined:
    Feb 17, 2015
    Posts:
    77
    Is there a particular reason why you can't just expose the ability to set an arbitrary TextMeshPro material on some text? It seems like UIToolkit is slowly re-implementing pieces of TextMeshPro like outline, but why not leverage all the existing great tooling you have?
     
    HugoBD-Unity likes this.
  44. sharkbitgamesdev

    sharkbitgamesdev

    Joined:
    Dec 2, 2019
    Posts:
    18
    A suggestion: when you good folk implement the <link> tag, please make it like in TMPro so that there are events upon hovering and clicking the tagged content so that we can use it to make more than just links. Like making those particular words trigger a tooltip or something of the sort. Thank you!
     
    HugoBD-Unity likes this.
  45. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    499
    The UI Toolkit rendering pipeline doesn't allow custom material yet. Unfortunately, we have to re-implement those text features as long as custom materials are not supported. I know custom materials are on the roadmap and that some time is allocated to it for exploration, but I can't provide a precise ETA.

    We are aware UITK lacks an event system for text (characters, words, lines, richText...), and this is an important feature missing. It's on the roadmap, I'll try to put more pressure, so it gets reprioritized.
     
  46. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Neiyra likes this.
  47. WavyRancheros

    WavyRancheros

    Joined:
    Feb 5, 2013
    Posts:
    176
    How about an abstract "Text" component so that I can do "GetComponent<Text>().text = "I am a button" without having to worry at all if it is a UGUI Text, a TextMeshPro Text, a 3D Text or any other kind of text component. Would solve a lot of problems.
     
    Ruchir likes this.
  48. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    Is there any progress on this? UI Builder only has the useless options of letter/word/paragraph spacing,
     
    HugoBD-Unity and MousePods like this.
  49. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    811
    HugoBD-Unity likes this.
  50. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    499
    @Stardog , @MousePods it's indeed been on the roadmap for a while, but more urgent tasks kept coming. I'll try to reprioritize these.
     
    Stardog and MousePods like this.