Skip to content

Prefer TMPro.SetText(string) over .text=string #441

Description

Problem statement

Many people use TMPro.text = string, which is not optimal.
TMPro has a .SetText method to set text. This is as fast for set text, and it can provide garbage free float additions, which is not possible with manual setting

Documentation: https://docs.unity3d.com/ja/Packages/com.unity.textmeshpro@3.0/api/TMPro.TMP_Text.SetText.html

Proposed solution

When TMPro.text = string is detected, upgrade to .SetText(string)
When said string has variable numbers, like .text = $"Number: {value}", upgrade to .SetText("Number: {{0}, value")
When said string is made from a stringbuilder in the lines above without modification, pass the stringbuilder into the .SetText variable

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions