Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Character Info with TMPro

Discussion in 'UGUI & TextMesh Pro' started by Kellyrayj, Feb 2, 2019.

  1. Kellyrayj

    Kellyrayj

    Joined:
    Aug 29, 2011
    Posts:
    933
    I'm attempting to get TextMesh Pro character data from the TMP_CharacterInfo class. I've modeled this bit of code from the examples. However when I run the code, the log prints a blank entry. Anyone got any thoughts?

    Code (CSharp):
    1. TMP_TextInfo textInfo = textMP.textInfo;
    2.         int characterCount = textInfo.characterCount;
    3.  
    4.         for(int i = 0; i < characterCount; i++)
    5.         {
    6.             TMP_CharacterInfo charInfo = textInfo.characterInfo[i];
    7.             Debug.Log(textInfo.characterInfo[1].character);
    8.         }
    My ultimate goal is to be able to instantiate unique prefabs at the size and position of each character in the TextMesh Pro component which I think I need access each individual character and their respective world position. I'd greatly appreciate it if someone might be able to shed some light on how I could do this.

    Thanks so much!
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    When are you running this code? In Awake, Start, Update?

    Take a look at the TMP_TextInfoDebugTool.cs script which you can add to any text object

    This script accesses the CharacterInfo to draw their positions so this should serve as a good example to learn from.
     
    UnityRaghu and Kellyrayj like this.
  3. PabloIH

    PabloIH

    Joined:
    Sep 20, 2014
    Posts:
    12
    Now that TMPro is included with unity I don't find that script. Is there a way to access this or should we include an extra package to support this DebugTool?
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    This script is included in the TMP Examples & Extras.