Search Unity

GUI.Label causes Font.CacheFontForText, CopyChannels, Mesh.AwakeFromLoad and Mesh.CreateVBO

Discussion in 'Immediate Mode GUI (IMGUI)' started by Digika, Oct 10, 2020.

  1. Digika

    Digika

    Joined:
    Jan 7, 2018
    Posts:
    225
    So I have two different OnGUI passes on different scripts, both output dynamic string Label in a form of:
    "Text1 99\nText2 34\nText3: 56.34\nText4: 56\0\0\0\0" etc

    The length of the string is about 500 chars.

    The issue I'm having is that while one OnGUI pass with simple GUI.Label takes 0.02ms and `GUI.INTERNAl_Call_DoLabel` shows only `Material.SetPassFast` and `Mesh.DrawVBO`, the second OnGUI call on a separate component/object has `GUI.INTERNAl_Call_DoLabel` doing a lot of extra calls:

    Font.CacheFontForText
    CopyChannels
    Mesh.AwakeFromLoad
    Mesh.CreateVBO
    Mesh.DrawVBO
    Material.SetPassFast


    This does not make much sense to me as 2 generated strings are virtually the same. I do not use any asian or some very special/rare-wide unicode characters, it is mostly ASCII. If I set the string to be literal static mockup for problematic OnGUI the issue goes away. If I change static literal to
    "literal + i.ToString()"
    the issue returns.
    I do not use any custom fonts, it just default Unity uses for IMGUI (Arial I believe).
    The OnGUI does not use any custom GUIStyle either:

    Code (CSharp):
    1. private void OnGUI()
    2. {
    3.     if (Event.current.type == EventType.Repaint)
    4.     {
    5.         GUI.skin.label.fontSize = 22;
    6.         GUI.contentColor = Color.white;
    7.         GUI.skin.label.alignment = myAligment;
    8.         GUI.Label(Rect, myString);
    9.     }
    10. }
    My biggest gripe with this bug is that the other OnGUI call does pretty much the same and even more (colored text, GUI.Box) and it has no such issues.

    Any ideas what can cause that?