Cached Text Generators characterCountVisible returning incorrect values

I’ll start off by saying there’s a good chance I’m misunderstanding something here, so apologies in advance if I missed something.

The way I understand it, if I have a Text element on screen and I want to return the number of characters that Unity believes are being displayed (before being truncated) I can find that character count via:

textComponentReference.cachedTextGenerator.characterCountVisible

It stands to reason that if I had the string length (easy to find), I could compare the two to figure out if something is getting truncated, and take appropriate actions from there…

However, I’m noticing that characterCountVisible is returning values that I’m not understanding - for example:

Text: Something

As seen on-screen: Somethi

Length: 9 (Correct)

characterCountVisible: 6 (WAT?)

I would really like to know what is going on here, so if someone could help me understand how characterCountVisible works, that’d be great. Because I’m clearly not picking up what Unity is throwing down.

Cheers!

Maybe it’s not updated?

Try “Canvas.ForceUpdateCanvases();” after assigning the text, but before checking the visible characters count.

@Agent654 Did you wait a frame after assigning the text?
From my experience, the cachedTextGenerator will lie to you if you don’t let it update by waiting for a frame, or maybe using Canvas.ForceUpdateCanvases().