UI Toolkit set text without allocating

I made a post about this a while back, but I cannot find it. Maybe it got lost in the migration to Unity Discussions.

Anyways, is there a way to set text without using a string in UI Toolkit?

TextMeshPro has SetText() API that take in StringBuilder, char[], etc.

Does UI Toolkit have similar functionality or is it planned in order to have feature parity with UGUI?

Hello! That’s been in the plans for a while but it hasn’t happened yet unfortunately. The team has worked on a many performance improvements in UITK’s text, such as jobification and an enhanced caching system. However, adding a method to set text with zero allocation is definitely something that needs to be done.

2 Likes

Awesome, thank you for the reply and insight!

Also I don’t know what the internal plans are here, but it would be really great if that method when added has an overload that takes in a ReadOnlySpan<char>.

This is something TMP_Text.SetText() is lacking.

1 Like

Yes, that was definitely part of the plan!

2 Likes

That is really great to hear, looking forward to seeing this in the future.