Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback Is this normal with Text Mesh Pro ?

Discussion in 'UGUI & TextMesh Pro' started by Nikhil12, Apr 2, 2019.

  1. Nikhil12

    Nikhil12

    Joined:
    Jun 1, 2015
    Posts:
    29
    Hi,

    I have made a very simple game. In the game after certain time I activate a canvas with few UI elements on it.(buttons and text). During profiling I found that text mesh pro is genrating lot of garbage. (check the attached image)
    The frame rate stays at 200 fps for most of the game but only for 2-3 frames it becomes 15 fps when I am activating a canvas with text on it.

    Is this behaviour normal ? How to fix this?
     

    Attached Files:

  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    When the first text object is awakened, certain resources like font assets, sprite assets, etc. need to be loaded along with managers. Then the text object itself needs to allocate its own buffers and depending on how many characters this text object contains, this will vary.

    There are also allocations related to the Canvas system, etc.

    Once these resources have been loaded, only new text object instantiation or changes in the number of characters needing to be displayed will result in additional allocation to grow the buffers of those text objects to accommodate the increase number of characters.

    Static text objects or text objects changing every frame where the number of characters doesn't exceed the block allocation (power of two) will result in no / zero allocation.

    So, worst case scenario is when the first text object is created and awaken with large quantity of text. This overhead should only occur once. You might want to experiment with on scene loading to create / awaken the first text object or some dummy text object with string.Empty to force loading the resources and managers which will shift this overhead to when the scene is loaded as opposed to when the first text object is enabled.