UI Toolkit text feature requests, highlighting, and/or allocation related

Today I’ve decided to give UI toolkit a shot by converting parts of a long running project to use the new system and I’ve run into a few limitations.

For this particular project i need to do a lot of runtime text modification, and try to do so in an allocation free way to reduce garbage collector overhead.

However the main use case for this text modification is to highlight text using rich text tags. And so with this in mind i figured there really needs to be a better way to implement this usecase since i can’t be the only one with this requirement.

So this post has a couple of requests in general all of which could in one way or another fix this issue:

  • Implement an api which doesn’t allocate to be able to set a char array instead of strings like TextMeshPro has
  • Expand the text selection style system to have way more styling options such as being able to style the text color (and maybe more?) which are selected and be able to drive this selection from code. Additionally it would be useful to be able to change the draw ordering of the selection rect to be above or below the text using styles. (And this should ideally work in a allocation free way, it shouldn’t just be building strings with rich text)

Would love feedback on this from others i think it would be a great upgrade giving these controls to developers.

A char array approach would be very convenient as well as it’d make a lot of old ugui code a lot easier to convert than if there’s a different approach. TextMeshPro respects null-terminated strings, so you can just have a large enough fixed buffer, pretend like you’re writing c, and it just works.

1 Like

Yes agreed, though i do think having the ability to have finer grained control over styling for selections is a useful feature as well. Which is why i mentioned both, but ideally having both would be an amazing improvement.