Search Unity

Performance drop with text mesh pro (OnEnable/OnDisable)

Discussion in 'UGUI & TextMesh Pro' started by Sly88, Feb 14, 2020.

  1. Sly88

    Sly88

    Joined:
    Feb 22, 2016
    Posts:
    73
    I see a lot of performance drop when I active/deactivate my object with text mesh pro. For example, for one object it is around 0.3ms. Is any chance to optimize it?

    thanks
     

    Attached Files:

    Rafael_CS likes this.
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    First, it is important to keep in mind that Profiler results do not reflect actual performance. Ie. 0.3ms in the Profiler is likely 5x to 10x faster in a build. Deep Profiler is even more drastic of a difference. Although the Profiler time results are no reflecting of actual performance, it is still great to identify parts of code that take more time to help identify areas of potential improvements.

    Having said all of that, enabling / disabling the text object forces a re-parsing and layout of the text as well as other things like removing from event list / re-adding / etc.. Now if the desired result is to hide the text, a much more efficient method is to disable the Mesh Renderer.

    Let me know if you are just trying to hide the text or if you need to really disable / re-enable it?

    P.S. As you are using the normal <TextMeshPro> component, disabling / re-enabling the text object doesn't impact other systems like disabling a <TextMeshProUGUI> object which depending on whether Layout Components are used would trigger a rebuild / re-layout of the canvas... ie. much higher performance cost when enabling / disabling canvas objects.
     
  3. Sly88

    Sly88

    Joined:
    Feb 22, 2016
    Posts:
    73
    @Stephan_B
    thanks for your prompt response. Unfortunately, I need to hide the object I can't only disable the Mesh Renderer. I thinking about overriding the text mesh pro class and remove few functions from OnEnable/OnDisable because I think a few redundant in my case. I didn't change the size and etc.

    or maybe you have a better idea?
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Disabling the MeshRenderer would hide the object / text without the additional cost related to enabling / disabling.

    It is also important to note that in the Editor, there is additional overhead related to Enabling / disabling so please be sure to Profile in a build and not in the Editor as you should see better performance.
     
    Sly88 likes this.