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

Localization & getting Line Count

Discussion in 'UGUI & TextMesh Pro' started by AntFitch, Oct 11, 2014.

  1. AntFitch

    AntFitch

    Joined:
    Jan 31, 2012
    Posts:
    243
    In my game, I need to count the number of lines to determine the height of a message box. If I was hard-coding the text directly onto the game object, this wouldn't be a problem and I would simply use cachedTextGeneratorForLayout or cachedTextGenerator. But these don't work when you change text at runtime (the original text info is always returned). Anyone know how to get things like the line count at runtime after text has been localized?
     
  2. s7

    s7

    Joined:
    Aug 7, 2014
    Posts:
    476
    I have run into a very similar problem. The line count don't just update on the same frame and it's giving a lot of headache since you have to do it either using a constant update checks each frame or might just end up with a check that will fire on the next frame once something changed ie screen resolution.

    I'm wondering if there's a way to actually update cachedTextGenerator for the Text so it will return correct line count on the same frame after the actual text has been changed?
     
    Last edited: Oct 12, 2014
  3. JAKJ

    JAKJ

    Joined:
    Aug 17, 2014
    Posts:
    185
    You can do Canvas.ForceUpdateCanvases: Expensive, but immediate, and all stuff will be correct right after the call.
     
    AntFitch likes this.
  4. s7

    s7

    Joined:
    Aug 7, 2014
    Posts:
    476
    I will try this. Thanks for the reply :)