Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

TextMeshPro TextInfo CharacterInfo from source

Discussion in 'Unity UI & TextMesh Pro' started by cantfindanamethatisntalreadytaken, Nov 9, 2018 at 12:49 PM.

  1. cantfindanamethatisntalreadytaken

    cantfindanamethatisntalreadytaken

    Joined:
    Sep 21, 2018
    Posts:
    4
    Hi I'd like to get CharacterInfo about a position in the TextMeshPro text and I can't see how to do it.

    Given the text is "<b>A</b>" the text length is 8 and textInfo reports characterCount is 2, I can find the textInfo about characterInfo[0] and it correctly returns "A"

    The length of the text is longer than the characterCount because of the tags used.

    What I want to do is find it from the index of the text not the resulting textMesh. In this example, I want to find the textInfo about text[4] which is, again "A"

    Is there any way, knowing the position in the original text, what the chracterInfo is based on the character position in the text?

    I can see ways to find text based on mouse positions etc but can't see how to do this.

    Thanks
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,780
    CharacterInfo contains information about the characters in the text. These are the visible characters and non-visible characters like white spaces. This excludes all rich text tag / meta data.

    The CharacterInfo buffer is allocated in blocks and as such its length will rarely match the number of character in the text layout. Information about the actual results of the layout of the text including character, word, line, etc count is contained in the textInfo.

    The CharacterInfo contains data about each character including an index which is the index of the character in the original string.

    The textInfo and its content is used in many examples provided with TextMesh Pro. To learn more about how to interact with element of the text. See example 12 and 12a and the relevant scripts. These are provided as examples and should be a good source to learn from.
     
  3. amateurd

    amateurd

    Joined:
    Nov 1, 2016
    Posts:
    12
    Hi thanks Stephan.

    I've got it sort-of working by holding a second array of integers for the original (pre-rendered) text, where each integer matches the position in the rendered text. Each time the text changes, I loop through the rendered text characters and update the array.

    A bit like CharacterInfo but the lookup is the other way around.