Why Japanese text turns into tofu boxes only in packaged Unreal Engine 5 builds
I'm a solo dev in Japan making small UE5 plugins for Japanese text. A while ago I packaged a test build, opened it, and half of a menu was just blank, even though the editor had drawn something there.
That one turned out to be a Rich Text Block without a Text Style Set (section 2), but it sent me looking for all the other ways text goes missing. The classic symptom is the empty box everyone calls "tofu" (่ฑ่ ). Google's Noto fonts are even named after it: "no more tofu".
If you ship in Japanese, or add a Japanese/Chinese/Korean translation late in the project, you'll probably run into some version of this:
- Fine in the editor, but some characters are boxes, ๏ฟฝ or just missing in the packaged game
- After adding translations, only the Korean or Chinese text breaks
- Japanese shows up, but a Japanese player tells you some kanji "look Chinese"
I got curious and dug through the engine source (UE 5.8). Here's what's going on.
Short version
There are three separate traps, and the editor hides the first two:
- The editor quietly adds fonts that your game won't have. Slate's default font gets extra typefaces only when
GIsEditoris true: emoji for everyone, and a Japanese or Korean one if the editor UI is in that language. In the game, kana, kanji and Hangul still draw (through DroidSansFallback), but emoji and rare kanji like ๐ ฎท don't. - The "last resort" font is editor-only too. In the editor a missing glyph still draws as some kind of box. In a cooked build Slate swaps in
U+FFFDinstead: you get ๏ฟฝ if the font has that glyph, and nothing if it doesn't. - UMG's default font draws Japanese with a Chinese fallback. No tofu, but ็ด, ้ชจ and friends come out in the Chinese style. This one shows in the editor too; it's just easy to miss.
So "it looks fine in the editor" really tells you very little here. That was the part that surprised me most.
1. Fonts that only the editor adds
Slate's default font (FCoreStyle::GetDefaultFont()) is assembled in FLegacySlateFontInfoCache::GetDefaultFont() (Engine/Source/Runtime/SlateCore/Private/Fonts/LegacySlateFontInfoCache.cpp). Besides Roboto and DroidSansFallback (the fallback typeface, there in every build), there are blocks like this:
// Japanese (editor-only)
if ( GIsEditor ) {
FCompositeSubFont & SubFont = . . . ;
SubFont . Cultures = TEXT ( "ja" ) ;
APPEND_RANGE ( SubFont , CJKUnifiedIdeographs ) ;
APPEND_RANGE ( SubFont , Hiragana ) ;
. . .
APPEND_EDITOR_FONT ( SubFont . Typeface , "Regular" , "GenEiGothicPro-Regular.otf" , . . . ) ;
}
Only when GIsEditor is true does the engine add GenEi Gothic (from Engine/Content/Editor/Slate/Fonts/) as the Japanese sub-font.
Note the Cultures line, though: FontCacheCompositeFont.cpp only uses a sub-font with cultures when the current language matches. So GenEi Gothic kicks in only if your editor UI is in Japanese. Korean (NanumGothic) works the same way, and the Chinese sub-font is just DroidSansFallback again.
The emoji sub-font (NotoColorEmoji) has no culture, so every editor gets it.
In a packaged game GIsEditor is false and all of these are gone. Kana, kanji and Hangul still draw, through DroidSansFallback. Emoji and anything DroidSansFallback doesn't have, like ๐ ฎท, are the ones that disappear.
2. The last-resort font is not in packaged builds
When a font has no glyph for a character, Slate tries the LastResort font (Engine/Content/SlateDebug/Fonts/LastResort.ttf). Whether it is available is decided like this:
bIsLastResortFontAvailable = ! FPlatformProperties :: RequiresCookedData ( ) && FPaths :: FileExists ( LastResortFontPath ) ;
With cooked data (a packaged game) it is never used. And it is Unicode's "Last Resort" font anyway: it draws a symbol meaning "a character of this block", not the character itself.
Without it, SlateTextShaper.cpp retries with U+FFFD (the replacement character):
- Editor: missing characters show a box with a symbol (sometimes you notice)
- Packaged game: ๏ฟฝ if the font has that glyph, otherwise nothing
A common case: Rich Text Block without a Text Style Set
A Rich Text Block takes its font from the Text Style Set (the row named "Default") or from "Override Default Style". With neither, the font is empty, and FSlateFontInfo::GetCompositeFont() (SlateFontInfo.cpp) hands back the last-resort font for every character.
The editor shows something; the game shows nothing. That was my blank menu.
3. UMG's default font draws Japanese in Chinese style
UMG's Text Block default font, /Engine/EngineFonts/Roboto, has no Japanese glyphs. The fallback typeface, DroidSansFallback, draws them. DroidSansFallback has Simplified Chinese glyph shapes, so characters such as ็ด, ้ชจ and ่ง look different from the Japanese forms.
It is not tofu, so it is easy to miss, but for a Japanese game you should import a Japanese font (Noto Sans JP, for example).
Roboto + DroidSansFallback also lack:
- ๐ ฎท and other characters in CJK Unified Ideographs Extension B and later
- Emoji (๐ etc.)
Comparison
The same string, shown with four fonts with -game. That turns GIsEditor off, so trap 1 shows up. It still runs UnrealEditor.exe, though, so the last-resort font is still there and missing characters show as its boxes instead of vanishing. For trap 2 you need a real packaged build.
| Font | Characters that did not draw |
|---|---|
| UMG default (EngineFonts/Roboto) | ๐ ฎท, emoji |
| Slate default (FCoreStyle) | ๐ ฎท, emoji (an in-editor check says they exist) |
| Roboto-Regular.ttf only | kana, kanji, Hangul, โ โชโ ๏ฝใฑโ, emoji |
| DroidSansFallback.ttf only | ร รฏ รถ รฎ รต, ๐ ฎท, emoji |
The second row is the trap: checked inside the editor it reports "all characters present", yet with -game they come out as boxes.
Checking glyphs in code
Slate's font cache can tell you whether a font can draw a character (in the editor or at runtime, as long as Slate is running):
#include "Fonts/FontCache.h"
#include "Framework/Application/SlateApplication.h"
#include "Rendering/SlateRenderer.h"
// Can Font draw C? (the last-resort font does not count). Call it on the game thread.
bool CanDraw ( const FSlateFontInfo & Font , UTF32CHAR C ) {
if ( ! FSlateApplication :: IsInitialized ( ) || ! FSlateApplication :: Get ( ) . GetRenderer ( ) ) {
return false ; // no Slate here (dedicated server, commandlet, ...)
}
FSlateFontCache & Cache = FSlateApplication :: Get ( ) . GetRenderer ( ) -> GetFontCache ( ) . Get ( ) ;
float Scale = 1.0f ;
const FFontData & Data = Cache . GetFontDataForCodepoint ( Font , C , Scale ) ; // picks the typeface inside the composite font
return Cache . CanLoadCodepoint ( Data , C , EFontFallback :: FF_NoFallback ) ; // does that typeface have the glyph?
}
Passing FF_NoFallback keeps the last-resort font out of the answer. But run inside the editor, this also picks the editor-only typefaces from section 1, so it reports "present" for Slate's default font.
The answer even changes with the editor's display language, because of the Cultures check. For an accurate answer, walk the composite font yourself (FSlateFontInfo::GetCompositeFont(): default typeface, sub-typefaces, fallback typeface) and ignore fonts under Engine/Content/Editor/.
What I do now
Import a real Japanese font (Noto Sans JP, Source Han Sans, whatever you like) and use it through a composite font. Don't rely on the defaults.
Every Rich Text Block gets a Text Style Set with a "Default" row. No exceptions - this one bit me twice.
Add a font for each language you translate into. Inside a composite font Slate only tries the sub-font, the default typeface, the fallback typeface and the (editor-only) last resort; it never borrows a glyph from another font asset. So if your Japanese font has no Hangul, Korean text in that widget has nowhere to go.
Rare kanji or emoji? Make sure some font in the chain actually has them.
Check in a packaged build (or with a check that skips editor-only fonts). Eyeballing the editor isn't enough.
Shameless plug
After hitting this a few times I turned the checks into a plugin, JpTextCheck (paid). It goes through widgets, Rich Text, DataTables, StringTables and text typed into Blueprint nodes, and lists tofu, Chinese-style glyphs, untranslated text and overflow per language: https://engineer-sasaki.booth.pm/items/9192082
I also put together JpFontPack, a free set of 10 Japanese fonts set up for UMG and Rich Text: https://engineer-sasaki.booth.pm/items/9203195
Both are on BOOTH, which has an English UI. If you've hit a different flavor of this problem, I'd love to hear about it in the comments.
Engine source referenced (UE 5.8)
Engine/Source/Runtime/SlateCore/Private/Fonts/LegacySlateFontInfoCache.cpp(default font, last-resort condition)Engine/Source/Runtime/SlateCore/Private/Fonts/FontCacheCompositeFont.cpp(choosing a typeface in a composite font,Cultures)Engine/Source/Runtime/SlateCore/Private/Fonts/SlateFontRenderer.cpp(glyph checks)Engine/Source/Runtime/SlateCore/Private/Fonts/SlateTextShaper.cpp(U+FFFDsubstitution)Engine/Source/Runtime/SlateCore/Private/Fonts/SlateFontInfo.cpp(empty font โ last-resort font)Engine/Source/Runtime/UMG/Private/Components/RichTextBlock.cpp(Rich Text Block default style)
Comments
No comments yet. Start the discussion.