Text or Textmeshpro and others?

Hello,

so for 2022, and I am using unity version: 2021.2.7f1 personal… is the old button, text etc being deprecated and we need to start using the new text textmeshpro or button mesh pro? can we still use the “legacy” objections, or are those being deprecated in the next few years? I am planning on creating a simple fun mobile game but want to make sure i am going to use the stuff that will be around… also use objections that wont have to much performance hit.

thanks in advance

Since the legacy text system which includes UI.Text and all other components using those text components are no longer on active development and will be eventually be deprecated, there is no reason to use those when TMP is still on active development and our text system going forward.

I’ll correct a bit of the statement made by Stephan_B.
First, we’ll call each with names that make it clear: “Legacy” for the old version and “TMP” for the Text Mesh Pro version.

As Stephan_B pointed out, on the long run, The Legacy text will be turned into deprecated as it’s currently no longer in active development and, as more updates and features comes into the engine. Whenever it will be removed due to issues or not is yet to be known. It’s basically in a stage of “It remains until it stop working properly.

Is it on its last leg? I highly doubt it unless either Unity Tech. decide to forcefully remove it or unless there’s some insane change in the rendering system of the game engine (which would ultimately also hit TMP and many other part of the engine, so we would hear about it anyway.)

Unity Tech and many devs evangelize TMP as being the only option because “There is no reason to use the Legacy since TMP is just superior or equal in every way.” (I’m summarizing all that is said about it.) That’s half-truth-half-BS.

TMP does offer more than the Legacy Text, but it also comes at a certain performance cost that isn’t negligible if you know what and where to look at. On the direct rendering pipeline (which affects average FPS), there’s barely any difference between the Legacy and the TMP, but on the Garbage Collection and Memory Block (especially on mobile), the difference is relatively high. TMP can have as much as 20x the impact on the garbage collection and Memory Block sizing than the Legacy Text. It’s not a bug or a problem or an issue, but just a result of all the additional bells and whistles you find in TMP that is simply none-existent in the Legacy texts. Remember that, in general, more options means more memory allocated to each of the options unless some kind of dynamic memory allocation is implemented so that only the changed (non-default) options actually have some kind of hit on deep-performances systems. Due to its “highly-customizable” nature, TMP doesn’t have much in terms of dynamic memory allocation.

Not many games uses proper dynamic memory allocation for its font/texts because it’s highly prone to bugs and issues on any slight hiccups. Path of Exile has suffered from such issue for a long while (news about it when it got fixed recently) as an example. It’s a common rabbit hole that never ends.

If you need to make use of the additional features that comes with TMP, obviously it’s better to use it instead of tinkering your own custom solutions that, in the end, might not even work better or faster. If you’re custom building some UI and/or interaction system and don’t need any additional feature of the TMP (you just need some text displayed in the UI with some basic functionalities), then you might want to stay clear from TMP and that’s especially if you’re doing lots of minor-adjustments or changes in real-time.

One good example I can give is if you’re loading some text into some text bubble dynamically in a way that makes the text slowly fill up (kinda like if it’s taught by some NPCs). As the text is added to the bubble, its size grows. While simple to do with the UI in Unity (resizing by the content), the setup behind the screen is complex like hell and it’s quite different between TMP and the Legacy Text when it comes to how much data is read and modified on each instance.

I’m not writing that TMP isn’t worth its additional weight, but just that the Legacy Text still has its uses.

For projects that aren’t yet reaching its limits in memory allocation, it’s always 100% OK to just use TMP, but when you see that a device starts having drop in performance when you enable, change or move a lot of UI element, including texts, you might want to look up how to downgrade TMP to the legacy whenever possible.

Since I’m a bit too much sophisticated when it comes to my projects’ UI, I’m one of the few who have seen some of the negative impact from using TMP everywhere. I ended up using it on semi-permanent UI element like menus and gameplay UI that doesn’t change much, but when it comes to dynamic automaton texts like dialogues and multi-layered adaptation in content based on screen size (especially for mobile devices), I’m using the Legacy Text. As soon as you hit that memory limit where some memory has to be cleared from the Garbage Collector for new one to be added, that’s where TMP hits far harder than the Legacy texts.

3 Likes

In terms of overall memory overhead, TMP does indeed have a higher memory overhead which mostly comes from hanging on to the TextInfo and sub data structures. This is something that I have been thinking about for a while which will be addressed as in some cases like Input Fields or when a user needs to modify the geometry of the text or query this data for their own purposed then we certainly need to provide for the ability to hang-on to this data but in the case of static text labels and some other cases, it is not necessary. This change will result in a significant memory overhead reduction.

In terms of garbage collection, other than the initial allocations, there should be no GC other than string allocation on the user’s end. That is none on the part of TMP unless the text grows in size by more than a power of two in length.

In terms of memory overhead and allocations for the legacy system, you have to be careful as some of those parts are in native code where those allocations are not visible in the profiler for instance.

In terms of performance, assuming a text string of the same length and plain white text, TMP should perform the same or better than the legacy text system.

In terms of added functionality, TMP offers a ton of additional features where some of them are fancier but there are lots like the ability to control character, word, line or paragraph spacing. More text alignment modes like Flush and Justified text, additional overflow modes like Ellipsis and line breaking for Chinese, Japanese or Korean which is essential for any project that need to support those languages. Support for inline graphics, sprites is also a big deal for many users. Ability to control your fallback structure both local and global or to use multiple fonts per text object and the list goes in. It is a ton of additional features.

5 Likes