Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Mese · Feb 20, 2018 at 03:43 PM · texturetextmesh

TextMesh Pro TextInfo not initialized on 'Start()'

I'm using the lastest versión of TextMesh Pro and I'm evaluating if it's going to be useful for my upcoming project.

But, when accessing 'textInfo', or 'GetParsedText()' from 'Start()' or 'OnEnable()', I get blank un-initialized data. How can I fix that? (I get TextInfo with WordInfo with dummy array full of nulls and uninitialized data, 'GetParsedText()' returns "") When this data gets done?

My final objective here is: I want to GET the screen (or world) position of EACH word, also their height and width... all within the same TextMesPro component. Also Lines. I know where they are and mostly how, but any advice on that would be also appreciated.

Finally, where can I find an API reference for TextMesh Pro. I've looking and couldn't find any. Methods are not commented and it's tricky to know who is who and what it does.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mese · Feb 20, 2018 at 03:47 PM 0
Share

I Found what I consider a "workaround". I ran "Canvas.ForceUpdateCanvases();" on my 'Start' $$anonymous$$ethod (before accessing the T$$anonymous$$P component). Now data is initialized (just like when I run from 'Update'). Still, this is weird, and I dont like forcing Canvases to Update just becaue... Any other way?

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by salehra · Dec 01, 2019 at 09:41 AM

You need to run ForceMeshUpdate method before reading textinfo @Mese

  m_textbox.ForceMeshUpdate();
  Debug.Log($" {m_textbox.textInfo.characterCount}");
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by oTaijjo · Dec 01, 2019 at 08:57 AM

TL;DR; Try calling textMeshPro.ForceMeshUpdate(), before accessing the TextInfo or the likes.

I'm not sure, if that's still around in the latest version, but TextMeshPro Components used to have a ForceMeshUpdate() method. We ran into issues that text meshes were updated too late in the frame, and with this method we could force the availability of 'up to date' mesh datat to be used, when needed.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by lucbloom · Mar 22 at 12:06 PM

That won't work if "Awake" hasn't been called on the Text component yet. This solution works always, by activating every parent in the tree up to the root, then restoring the active state of each.

 public static int GetLineCount(this TMP_Text label)
 {
     var disableds = label.transform.EnumerateAllParents(true).Where(p => !p.gameObject.activeSelf).ToList();
     disableds.ForEach(p => p.gameObject.SetActive(true));
     label.ForceMeshUpdate(true);
     if (label.textInfo == null)
     {
         Console.Log($"Label {label.name.Quoted()} doesn't have a 'textInfo' object. This is usually because it has not been 'Awoken' yet. activeSelf: {label.gameObject.activeSelf} activeInHierarchy: {label.gameObject.activeInHierarchy}");
         // Try to salvage:
         return label.text.Empty() ? 0 : (label.text.Count('\n') + 1);
     }
     disableds.ForEach(p => p.gameObject.SetActive(false));
     return label.textInfo.lineCount;
 }

Utility:

         public static IEnumerable EnumerateAllParents(this Transform go, bool includeSelf = false)
         {
             if (!includeSelf)
             {
                 go = go?.parent;
             }
             while (go)
             {
                 yield return go;
                 go = go.parent;
             }
         }
         public static string Quoted(this string s) => s == null ? "null" : $"\"{s}\"";
         public static int Count<T>(this IEnumerable<T> container, T v) { return container.Count(x => EqualityComparer<T>.Default.Equals(x, v)); }
         public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSource> actor) { foreach (var x in source) { actor(x); } }


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

100 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to add text on avatar material dynamically in unity? 0 Answers

Can I get color(or grey scale value) array for a font given a font size without using render texture? 0 Answers

Using shaders for text effects (TextMesh) 0 Answers

How to access a Text Mesh Pro Font Asset's glyp info from c#? 1 Answer

Writing your name on jersey from input 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges