Search Unity

[5.2] Terrible performance spike causing by Font cache

Discussion in 'UGUI & TextMesh Pro' started by BenouKat, Sep 9, 2015.

  1. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Font issues on ios been happening for years now, not sure why unity shocked, issues been raised on ios section of platform in much detail. Not a proper solution was given in earlier version.. My hack and long hack.. Use text mesh pro plugin from asset store, stops the spikes from happening... Having said that i cannot confirm if issue still exists in 5.3.5
     
  2. pfreese

    pfreese

    Unity Technologies

    Joined:
    Feb 23, 2015
    Posts:
    85
    Ironically, this will cause CacheFontForText to be called each frame that the UI changes. The overhead of this call is very little if no work needs to be done.

    You should be able to get the same effect (with less hackery) by calling Font.RequestCharactersInTexture() each frame, which should prevent the glyphs you are using from getting evicted. I still don't understand why you are seeing such a stall from rebuilding the font texture atlas.
     
  3. DannyHellfish

    DannyHellfish

    Joined:
    Jan 20, 2014
    Posts:
    29
    @pfreese I have it on a separate canvas so the canvas never changes. The problem I still have is that if I use best size ( which I must do for some labels due to the differences in string-length depending on the loca ) it still recaches it every goddamn time the font size changes (even when it gets smaller) and causing spikes even for smaller labels (only on iPad, no problem on iPhone 4s... So I guess its caused by a mixture of performance and screen resolution )

    @MrEsquire The problem with text mesh pro (which is an awesome plugin) is that it uses font textures and increases the build size enormously if you have large font sizes and 16+ languages (lot of them asian) therefor pushing my build size over 100mb. That's why I have to use dynamic fonts...
     
    Last edited: Jun 28, 2016
  4. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Just curious.. how viable is it to use AssetBundles, and only download which Bitmap Fonts are needed?
    You can create an Options dialogue that shows a Preview of the fonts, using certain chars only, just to let your user know what it looks like before downloading the AssetBundle of that bitmap font. I'm just speculating. Never did anything like this before. Sorry. :[

    I might look into adding something of the sort as an optional thing to my kissUI asset too. :]
     
    Last edited: Jun 29, 2016
  5. DannyHellfish

    DannyHellfish

    Joined:
    Jan 20, 2014
    Posts:
    29
    Could be that its doable from a code perspective but from a game design point of view I want the player to experience the game as quickly as possible without any further steps. I think that players on mobile have no real patience for downloading stuff before playing. (Especially when its a minimalist puzzle game and not some AAA mobile game)
     
  6. pfreese

    pfreese

    Unity Technologies

    Joined:
    Feb 23, 2015
    Posts:
    85
    To reduce the amount of thrashing of the glyph atlas during best fit, try constraining the min/max best fit size to be as tight as possible. Since the text generation uses a binary search, the tighter the constraints, the fewer the amount of attempts it needs to find the right size, which means fewer font atlas invalidations.
     
  7. RGM90

    RGM90

    Joined:
    Jan 11, 2016
    Posts:
    4
    I recently had the same issue running Unity 5.6.1. I was trying to update a UI text component frequently (at around 10Hz).

    I fixed the issue with the following:

    Text Component
    Turn off 'Best Fit'.

    Font Import Setting
    Set 'Rendering Mode' to 'OS Default'
    Set 'Character to 'Custom Set'
    Set 'Custom Chars' to my required chars: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ !