Search Unity

How do I get character count?

Discussion in 'UGUI & TextMesh Pro' started by VaygrEmpire, Jul 24, 2019.

  1. VaygrEmpire

    VaygrEmpire

    Joined:
    Sep 30, 2016
    Posts:
    40
    Code (CSharp):
    1. int totalVisibleChar = textMeshProUGUI.textInfo.characterCount;
    above code returns 0.

    attached file shows I have texts written inside Text Mesh Pro UGUI.

    What's happening here?

    Did you guys change characterCount into something else? (coming from 2017. finished all migrating stuff based on guide already. This is script issue - teletype writer effect - because things work when script is disabled)
     

    Attached Files:

  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Until the text object has been rendered, the textInfo won't contain any valid data yet.

    When are you checking the characterCount? Ie. in Awake() or Start(), etc.

    If you need the text object to be processed / rendered right away, you can always use TMP_Text.ForceMeshUpdate()
     
  3. VaygrEmpire

    VaygrEmpire

    Joined:
    Sep 30, 2016
    Posts:
    40
    I'm calling it in Start(). Also, thanks for help! It's working fine now.
     
    Hozgen90 likes this.
  4. Hozgen90

    Hozgen90

    Joined:
    Jan 20, 2021
    Posts:
    19
    working like hell!!! :D thanks bro!