Search Unity

Question Text Mesh Pro Detect isTextOverflowing

Discussion in 'Editor & General Support' started by Blenderik, Nov 21, 2022.

  1. Blenderik

    Blenderik

    Joined:
    May 14, 2013
    Posts:
    146
    I am trying to set the text of a Tmpro UGUI to alignment right when the text is overflowing. The end of the string is more important in this case. But:
    Code (CSharp):
    1.         MyTxtUGUI.SetText("My Text Long text..............");
    2.         MyTxtUGUI.ForceMeshUpdate();
    3.         print("Overflow: " + MyTxtUGUI.isTextOverflowing);
    always prints false, no matter how long the text is.
    I set the overflow to overflow and truncated. I set the wordwrap to true and false. No difference.
     
    Last edited: Nov 21, 2022
  2. Atomiz2002

    Atomiz2002

    Joined:
    Feb 2, 2020
    Posts:
    14
    same. even though i keep spamming out the input field.
    Code (CSharp):
    1. private TMP_InputField inputField;
    2.  
    3. private void Start() {
    4.     TryGetComponent(out inputField);
    5. }
    6.  
    7. private void Update() {
    8.     Debug.Log($"{inputField.textComponent.isTextOverflowing}");
    9. }
    upload_2023-6-20_13-40-39.png
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,674
    And that won't change because that is documented behavior.

    Always start with the docs.

    Screen Shot 2023-06-20 at 8.17.02 AM.png
     
    spiney199 likes this.
  4. Atomiz2002

    Atomiz2002

    Joined:
    Feb 2, 2020
    Posts:
    14
    how is returning false when exceeding the vertical bounds text container documented, because i see the exact opposite. this is why its mind bugging, and yes, i do always start with the docs thank you.

    here is my case. and im using the default template for creating an input field.

    upload_2023-6-21_9-30-11.png

    upload_2023-6-21_9-30-25.png

    upload_2023-6-21_9-28-29.png

    my script is attached to the InputField (TMP) object. and if the shown on the last image is not text overflowing, could someone clarify what is?
     

    Attached Files:

  5. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    307
    I know this is a old thread but just in case anyone else is having issues getting a true on the "isTextOverflowing" property, I put the check under the update method then it worked for me like so:

    Code (CSharp):
    1.     private void Update()
    2.     {
    3.         isOverflowing = text.isTextOverflowing;
    4.  
    5.         if (isOverflowing)
    6.         {
    7.             text.fontSize -= 5f;
    8.         }
    9.     }