Huge lag spike when activating a UI.Text GameObject.

Basically I activate (using SetActive(true)) a UI.Text GameObject when the player touches a book. When this happens the first time I get a huge performance hit visible in the profiler:
Canvas.SendWillRenderCanvases() (46.4%) : Font.CacheFontForText (8.4%)!

Why? Can I avoid this?

I tried making a script that reactivates the UI.Text GameObject, but this will then cause a: CanvasUpdateRegistry.PerformUpdate() (77.0%) -> Graphic.Rebuild() -> Text.UpdateGeometry()! How can the UI be so expensive? This seems horrible. o.o

Basically I'm on Windows 7 with a 3.5GHz processor and 970 GTX and I get horrendous FPS drops due to a SINGLE UI.Text! ...

2 Answers

2

It might be because the canvas your text is on has pixel perfect checked. Pixel perfect can cause performance issues in some cases.

I dont have pixel perfect checked since I'm using World UI scale mode.

You tip saved my project at last moment, Thank a LOT... :D

Check font settings of the text you use on your UI.Text.

Having insanely high ‘Font size’ increases the generated font texture and that might yield to what’s happening to you. Check the character set as well.

I usually go with
Font size : 64
Rendering mode : smooth
Character : ASCII default set

The font size was not the problem. However, I cannot find "Rendering mode: Smooth". Where can I find this?

Thanks! :)