I’m making a game that prominently includes a mechanical typewriter. I’m using TMP for rendering the text to a render texture. Since the typebars have to strike where new letters appear, I have to know where letters are.
The way I’ve been achieving this is fixed width fonts, and wrapping the whole thing in a mspace tag, and calculating. Some subtle bugs make me loose sync sometimes. This isn’t intractable, but it would be real nice if I could completely delete that system in favor of knowing the position directly. That would also help me with some fx that are more or less impossible right now.
Any kind of position and I can work out the transformations. Position relative to anchor, UV position of last blit, worldspace position of letter’s next of kin, whatever.
When a text object is rendered, the textInfo data structure is populated. This textInfo contains sub structures that contain information about every character, word, line, etc. including the geometry. By accessing this textInfo and the relevant sub structure, you can get the position of each character which is how for instance the TMP Input Field determines where to position the caret relative to characters.
In the TMP Examples & Extras, there is a script called TMP_TextInfoDebugTool.cs which you can add to any text object. This will enable you to visualize the content of the textInfo but more importantly, give you a better idea on how to access this information.