Author Topic: Dynamic font labels are missing characters, flash, and jumble letters.  (Read 4549 times)

tydygunn

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 20
    • View Profile
Hello!

I'm currently using Unity 4.2.2 with NGUI 3.0.4, and I'm having issues on mobile (specifically Android at this point) devices. My UILabels are all dynamic, but have some intense issues ranging from leaving random letters unrendered, flashing on and off, and drawing the wrong atlas area (so instead of rendering a character, it'll render half of the character and then half of another character inside the same space).

When these issues occur, it happens with all of the labels on the screen currently using that font, and forcing a change in one of them (and by extension forcing a re-draw) the issues are usually resolved. That said, these issues are very noticeable to the end user.

I'd rather not update NGUI this late in a project if I don't have to, but I will if it means avoiding changing every single UILabel to a bitmap font. Ideas?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: Dynamic font labels are missing characters, flash, and jumble letters.
« Reply #1 on: January 04, 2014, 08:57:47 AM »
You should always update if you've run into an issue.

That said, you can also resolve your issue in 3.0.4 by pre-filling your font. NGUI calls font.RequestCharactersInTexture(text, size, style) to ensure that the characters labels need are present in the font. Unfortunately Unity is quite fragile here, and can easily break from my experience. If you request the characters you need (passing "abcdefgABCDEFG" etc as the text) with the size and style you need in Awake() or Start(), you should be fine.

You might also want to disable the "keep crisp" setting on your labels, or resizing label height will also change the font size, which should not be done on mobiles.
  1. using UnityEngine;
  2.  
  3. public class RequestChars : MonoBehaviour
  4. {
  5.     public Font font;
  6.     public string text = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  7.     public int size = 20;
  8.     public FontStyle style = FontStyle.Normal;
  9.  
  10.     void Start()
  11.     {
  12.         if (font != null) font.RequestCharactersInTexture(text, size, style);
  13.     }
  14. }