How to implement notdef symbol in Godot?

Godot Version

v4.5.stable.official

Question

I am using a pixel-style font in my game and recently ran into an issue with emojis. My font doesn’t support them, however they are still being displayed.


I guess Godot falls back to some default font which supports emojis, but I don’t actually want that. I would prefer them to be displayed as notdef symbol, something like this: □. So that they could still be pixel-y.
However, I cannot find this feature anywhere. Sure, I can write a function, that checks every symbols and replaces it if it is not present in the font, but I don’t think that is optimal + I don’t want to drag it everywhere.
Is there a way to set such a symbol?

2 Likes

Double click your font resource, deselect Allow System Fallback and click reimport:


You will now get tofu for every symbol not represented by the font.

2 Likes

Why would there be emoji in the texts?
Are the players going to create them like text input? Then you should maybe implement ‘allowed character’ check anyway.

2 Likes

@lastbender No, I have multiplayer via Steam. And people can have them in their usernames.
However, I guess you are right. There should not be that many cases where emojis can get through, so I can parse them in code.

2 Likes

I see. Then I think I’d create (or find online) pixel style emojis. Because it’d look really nice with your artstyle :slight_smile:

2 Likes

Do you know if there is a way of changing the default tofu font or its size? My font is really small and the tofu glyphs are way too big in comparison.

1 Like

I’m not sure why that happens, but you cannot modify individual glyphs from a font file (for example making only the letter A bigger/smaller). I’m also not sure if the missing glyph is handled by the font itself, but one idea that you could try is add a different fallback font that has the same missing glyphs as your intended one, and see if that works (no clue what the result would be; will Godot even fallback to a font that also doesn’t have that glyph?)