Skip to content

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

@smitdylan2001

Description

@smitdylan2001

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

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