- Home /
Efficient uGUI Text scaling on mobile (Not Best-Fit)
Hello community,
I have been developing games with Unity for a while ( >2 years full time) and there is a particular thing that bugs me to no end. The issue is easily explained (and reproduced): imagine a text that changes dynamically while playing, such as a Score. You don't want to give the text a fixed font size because you want to support multiple screen resolutions / pixel densities, so you have to scale it.
Using Best-Fit is what I have been doing to tackle this issue, however it has several downsides, such as being really slow (some dev working at Unity admited its performance was pretty bad). However, the biggest issue I have is that if a text uses Best-Fit and its content changes to have a different number of characters (e.g. adding digits - Score changes from 10 to 100) the previous font size is no longer valid and Best-Fit fires again to find the ideal font size, which involves really noticeable lag spikes due to having to regenerate the font texture.
I know about the API function that requests characters with font size so that this does not happen on runtime (http://docs.unity3d.com/ScriptReference/Font.RequestCharactersInTexture.html), however, this does not solve my issue because I don't know which font size to request. You usually have several texts like these in a game, so the problem intensifies (I don't think requesting a font texture with multiple sizes like font size 20 to 80 is a good idea at all).
I have researched several times for a solution for this and I have not found conclusive results. I really hope that this is because there is something extremelly silly that I have overlooked :) If not, what is the industry's standard practice?
Thanks!!