Change all game TMP fonts at one place?

Hello,

if I understand it correctly best approach for multi-language support is one TMP font for most of the languages and separate one for Chinese, Korean, Japanese. Theoretically I could use only first font and have others in it’s fallback, but I suppose it would have significant performance impact for language versions in fallback, as I have hundreds of objects with TMP component in game hierarchy at the same time.

So best option seems to be just swap all the game TMP fonts when language is changed…? But I struggle to imagine how to do that. I have hundreds of different prefabs which may or may not have TMP component, so I should scan every one after instantiation for TMP and change font eventually? It seems to be very inconvenient and would probably hit performance a bit in some cases. Plus some prefabs may already be instantiated or directly referenced in hierarchy, which complicates it even more.

Best way would be to have some global fonts set in TMP settings and possibility for TMP components to reference these fonts. So in case of runtime language change I would just programmatically change global font(s) and all TMP components referencing it would automatically work with it.

Would something like that be possible or maybe already is possible and I am missing it?

Michal

Since localization can involve more than just text like visual styling, icons, sounds, etc. many user use tools like I2 Localization which track all assets with respect to how they can be affect by localization choices. So I recommend checking those types of localization tools.

On the flip side, many users have developed their own solution which involves implementing some type of manager that tracks all text assets that are affected by localization. This essentially involves a reference to each text object and how their settings (including font selection) is affected by language choice.

It would be interesting to get feedback from other TMP user to provide insight on what their own solution entails.

Hello Stephan,

Thanks for an answer.
I work on long-term project, so I try to limit amount of dependencies on third party assets. It usually have some overhead you don’t need, can impact performance, stop working with newer version of Unity till updated or even become abandoned in future.

I can surely track all my game objects with TMP component and swapping fonts, I’ve just thought that having possibility to set central fonts which can be referenced from components would be very convenient way to do it.

I would be also interested to get some feedback from experienced users.

Michal

Same problem. Is it better to add Asian fonts as a fallback to the main font or scan the whole scene and change the font of all existing and future TMP components?

One approach I am currently experimenting with is using stylesheets. In theory that should allow swapping all the fonts by assigning new default stylesheet in one place without having to track down each TMP component. You just have to remember assigning some style when creating a new text component. One minor quirk I observed is that the tags defined in the configuration for “normal” style are ignored.

I made language and font switching the following and it works very well:

A manager class listenens to a language change event and loads the assigned fonts for all font styles for the new language from the resource or a remote folder.

As for most localization systems you need to add a extra component to the game object with the Text Mesh Pro component. In case of the mentioned I2 Localization it is the I2 Localize component. I also attach a selfmade component which registers on the same language change event. It gets the current font for the given style from the manager and sets it to the text. By the way it also supports changing the text font size.

I got lots of resistance of my collegous about adding a component to each text. I don’t understand this. Do a prefab for texts. And the selfmade component does other useful things like set the style with an enum, handle behaviour when to (not) swap right-to-left text or equalize font size, limit the maximum and minumum font size, warn about unwanted line breaks and so on.

As for asian font, you can set a latin font as fallback in the Text Mesh Pro settings. Asian fonts contain A…Z, a…z and 0…9, but not the special latin characters.

I integrated the top 20 languages with the TMP dynamic font features and a dozent source (otf, ttf) files. They use about 36 Megabyte on media and increase the app size for Android about 18 MB. I found now way to get below that size.