Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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
0
Question by viesc123 · Nov 09, 2021 at 01:11 PM · guitextunicode

TextMeshPro does not evaluate unicode fallback font when setting dynamic text?

I'm using strings with unicode characters to show controller icons in tutorials. A string would be for example "Hold \U00100a47 to run.", where \U00100a47 maps to a character in a fallback font that represents for example the action button on a controller.

alt text

This works fine when I paste the string into the TextMeshPro UGUI component it in the Inspector, however it does not work when I set the string dynamically at runtime via

 myText.text = "Hold \U00100a47 to run.";

If I do that, then the text will appear just like the string, with the unicode sequence appearing as plain text.

alt text

What do I need to do to make TMP update the mesh and evaluate the unicode correctly?

hold-to-run-correct.png (13.1 kB)
hold-to-run-broken.png (10.1 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by viesc123 · Nov 09, 2021 at 03:51 PM

Ok, dug into TMPro's code a bit and it turns out that if you enter a string via the inspector, some code parsing happens under the hood that does not happen when you set a string directly via tmpLabel.text = "..". If entered into the inspector, TMPro will actually convert the escape sequence to the specific UTF32 character and use that for rendering. It uses a bunch of private int array classes to represent the string, so it's pretty hard to recreate the code from the outside.

!!

BUT

!!

It turns out that you can force the same parsing by calling the TMPro label's OnValidate method after setting the string. Since that method is private too, I had to use reflections.

 myTutorialLabel.text = GetTutorialString(); // set the string containing the escape sequence
  
 // now call myTutorialLabel.OnValidate() via reflection
 var onValidate = typeof(TextMeshProUGUI).GetMethod("OnValidate", 
     System.Reflection.BindingFlags.Instance 
     | System.Reflection.BindingFlags.NonPublic);
 onValidate.Invoke(myTutorialLabel, null);

This is pretty hacky. It would be nice if TMPro allowed a simple use of their text parsing from the outside...

Comment
Add comment · Show 2 · 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 viesc123 · Nov 09, 2021 at 04:52 PM 0
Share

Ok, no solution, unfortunately. OnValidate does not exist in builds... head explodes

avatar image viesc123 viesc123 · Nov 09, 2021 at 04:56 PM 0
Share

There is another method I might try called SetTextInternal(string)... will give it another try some other time.

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

216 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 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 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

I want pixelated unicode text. Need suggestions... 2 Answers

Why aren't asian fonts rendering dynamically? 0 Answers

New GUI - Text not rendering in front of geometry if using a Mask 1 Answer

How do I get my GUI text to open on awake? 1 Answer

Trailing effect with GUI 0 Answers


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