some UI.Text objects disappearing with custom font

I’m using a custom font in my game and have noticed that recently some of the Text objects are no longer rendering. If I change the font back to Arial then they render. I can also get it to render again if I change the custom font from dynamic to unicode, but if I increase the size of the font (from 16, as it’s blurry) to a higher number, it starts to disappear again.
I would put it down to an issue with the font atlas if none of the text was rendering, but most of it is, it’s just a few objects that aren’t.
It’s important that I’m able to use the same font everywhere for consistency.

Has anyone experienced similar issues and know of a solution without compromising the sharp text rendering?

The version of Unity I’m using is 4.6.2f1.

EDIT: It must be an editor bug - it works when maximised on play, and it appears to be working on mobile ok.

My repro is insanely simple.

  1. Have UI Text items with dynamic font in the Scene window.
  2. Switch to another application.
  3. Switch back to Unity Editor.
  4. See all UI Text items disappear.
  5. Resize the Scene window by one pixel.
  6. See all UI Text items magically re-appear.

That sounds like your text is bigger than the width and height of the game object and you have the Text overflow set to hide things that don’t fit.

You have different options:

  • Set the overflow to “Overflow” in both directions. This will make ANY text always visible, the bad thing about it is that the text might be bigger than the area you defined for the UI element, overlapping other elements.
  • Increase the size of the area using the Rect Transform until the text is visible. You control the size of the object, but you have to do it every time you change a text.
  • Turn on the “Best fit” option on the Text component. With this method you get a constant size for you object and the text will always fit, but Unity will change the font size automatically, which may be bad for some cases.
  • Add a Content Size Fitter component and set horizontal to “Preferred size”. This way the text will always be inside the area with the font size you selected, but the area will get bigger or smaller depending on length of the text inside.

Edit: It probably works Maximizing or in a build because of how Canvas Scaler works, I guess for some resolutions the font size might be a little bigger.

@Skully
Check the “Best Fit” option in the Text section of the Inspector. It will give you two extra options of Min and Max size. Set the max size to your text size and you can set min to either 0 or the same value as the max.

This solved the issue for me. Hope this helps you.

I’m having the same problem:

I have a label with a custom imported font. Lot’s of different text strings work perfectly, but one does not show up when set dynamically.

  • I’ve tried increasing rect size to riddiculously big.
  • I’ve tried overflow in both directions
  • I’ve tried best fit
  • It does work on Maximize on play (I’m using a canvas scaler - maybe that’s part of the problem?

The wierdest thing is that the text ONLY dissapears if there is a space character among the first 20 or so characters.

  • There can be spaces later in the string.
  • It reappears immediately if any early spaces are removed using the inspector.
  • It dissapears immediately if a space is added within the first 20 characters (but not if the space comes later in the string).
  • Other strings set from code are allowed to have spaces also within the first 20 characters.

In conclusion the error is so random it must be a bug, in my oppinion.

For me this issue was caused by PlayMaker but unless you’re also using that you’re probably having a different issue to me.

One more thing to try for people ending here and tried the other solutions:

In your Text object make sure the Material is set to the fonts material.

I had a similar issue, and the culprit was the corruption of the default UI material (which is the one used when you don’t assign a specific one to your UI element). This can happen if you have a script accessing the .sharedMaterial property.

also Untick the Maskable Option From Text Component