Search Unity

Resolved TextMeshPro Update GC in Editor

Discussion in 'UGUI & TextMesh Pro' started by DreamingImLatios, Aug 26, 2022.

  1. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,270
    Currently, even when using the StringBuilder APIs, setting new text in TextMeshPro causes GC allocations, which is annoying when trying to remove all GC allocations in a project. It does this to update the inspectors, even if the inspector isn't focused on the text.

    There used to be a way to not have this. Can we get some global switch or something to turn it off?
     
  2. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Would be great if TMPRO.SetText could accept Span (ReadOnlySpan<char>) too!
     
  3. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    499
    Hi! I am a developer from the Text Team. I primarily work on integrating TextCore into UITK, but I am expected to also work on TMP in the near future.

    We are actively working on improving the performance of the TextGenerator. At the moment, we are focusing on decreasing its memory footprint. One of the following performance improvements we would like to investigate is to ensure we do not generate new GC allocs for a TextComponent that's being updated every frame. I'll take note of your point, but it's possible we can't hold that promise for the Editor as turning it off might break the inspector.
     
    karl_jones likes this.
  4. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    499
    @TJHeuvel-net it's a really interesting idea, that we do plan to explore. We were holding it back as Span is only available in C# 7.2 and above, so it wouldn't have been compatible with 2019.3.
     
  5. Saniell

    Saniell

    Joined:
    Oct 24, 2015
    Posts:
    194
    And what is stopping you from using #if UNITY_WHATEVER_OR_NEWER define exactly?
     
  6. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    499
    We could have, but we try to use them sparingly and depending on the complexity of the change. Having compiler define spread across the code base is not great for readability and maintenance.
     
    TJHeuvel-net likes this.