I haven’t verified it yet and am basing my assumption on the log, but it seems that if I load UIs designed from separate .castle-user-interface files with their own TCastleFont, CGE will create a new font texture even if they are completely identical. If this is the case then it is very concerning, especially since I plan to include support for Japanese charsets in the future (huge texture font with a long loading time!) or if I design a UI intended as items in a list and load it multiple times.
We indeed don’t cache the underlying font images / glyphs for now. So if you use TCastleFont with the same settings (URL etc.) in multiple designs, each design will load it independently.
I agree it’s a problem, I have TODO about this.
For now, the workarounds (for cases when it is problematic) are to not customize font by creating TCastleFont instances in the editor. Instead:
- To change the default font, change it in
CastleSettings.xml, Customize look by CastleSettings.xml | Manual | Castle Game Engine . Or assign different value toContainer.DefaultFont. - To control it more, change font from code. You can then create one/few (as little as you need)
TCastleFontinstances, and share them as needed across multiple designs.
I know, the above is complicated – and it means you cannot customize font at design-time (except CastleSettings.xml, other advises above mean that you only see customized font at run-time). So we should make it better some day ![]()
I chose option 2 but took a step further: I manually parse the JSON to identify UIs with custom fonts, remove the custom font from the JSON, and assign the appropriate TCastleFont instance to the deserialized UIs. This way I can keep custom fonts in the design file.
faced the same issue (I used second font on generated controls in addition to default_font configured in castlesettings, I’ve overcome it by merging the fonts in FontForge into one) and here is my sample project to reproduce, I’ve exaggerated generation amount which causes noticeable perf drop on load.
my-new-project.zip (51.6 KB)
I remember I had similar issue (discussed in discord on may 2024) with spritesheets when I was loading designed UI multiple times, it really hit performance bc of lack of caching them
