• 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 /
  • Help Room /
avatar image
Question by ActualDog · Sep 24, 2015 at 05:50 PM · fontfonts

Inconsistent results with Font.GetCharacterInfo()

Ok, so, I feel like I'm going insane. I'm just recently upgraded to Unity 5.2 and I'm getting very inconsistent results with GetCharacterInfo().

I've been using it for a conversation system to get the width of my words so they preemptively adjust themselves as they display letter by letter and don't overflow the text box or auto-adjust mid-word.

I've started noticing inconsistencies with t$$anonymous$$s implementation, but it seemed to be working just fine in the past (it's also just possible I've been stressing it more recently).

So, I have t$$anonymous$$s block of code that hopefully explains my issue:

 for (int i = spewPos; i < currentTextSpew.Length; i++)
 {
     if (currentTextSpew[i] == ' ')
     {
         break;
     }
 
     bool result = usedFont.GetCharacterInfo(currentTextSpew[i], out currentInfo, fontSize, fontStyle);
     if (!result)
     {
         failedChars.Add(currentTextSpew[i]);
     }
     else
     {
         if (failedChars.Contains(currentTextSpew[i]))
         {
             print("A character that previously failed is now returning a valid result.");
         }
 
         foreach (char failedChar in failedChars)
         {
             result = usedFont.GetCharacterInfo(failedChar, out currentInfo, fontSize, fontStyle);
             if (result)
             {
                 print ("T$$anonymous$$s character used to fail GetCharacterInfo but now does not: " + failedChar);
             }
         }
     }
 }

In English, I'm seeing GetCharacterInfo() fail to return results for a specific character, but then correctly returning results for that character at a later point in time. If GetCharacterInfo() fails to return results for a specific character, it will continue to fail if the frame has not advanced, but after more frames have passed, it will eventually succeed again.

Am I doing somet$$anonymous$$ng horribly wrong here? Do I need to mess with font import settings to preload t$$anonymous$$s information? I'm happy to provide more specific info about what I'm doing if needed.

Any help at all would be greatly appreciated!

Comment
Lao2211

People who like this

1 Show 5
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 ActualDog · Sep 24, 2015 at 07:53 PM 1
Share

Just FYI, I have more information. The specific issue seems to be that GetCharacterInfo() does NOT return valid results for any character that hasn't yet been rendered.

As soon as a character has been rendered, that function works perfectly. My workaround right now is to set the text of a hidden textbox with the same properties as the one I'm trying to use to a string of every possible character before I actually try to show anything for real.

This feels pretty gross to me though, so I'd still love to hear any other thoughts people might have. This feels like the sort of thing that I should be able to work around with an import setting somewhere.

avatar image goneale · Mar 29, 2016 at 06:19 AM 1
Share

I'm a bit late to the game here, but @ActualDog, you should try adding Canvas.ForceUpdateCanvases(); just prior to the GetCharacterInfo() calculation, this did work for me, where in some cases it wouldn't evaluate the size correctly. Now it does every time.

avatar image Lao2211 · Mar 17, 2017 at 11:46 PM 0
Share

It's works. And forcing canvas to update too. You should post as answer and mark your own answer as the solution so this question remains as solved.

avatar image alifaris · Apr 21, 2017 at 02:34 AM 0
Share

I have the same problem. But I noticed If I stop unity and then rerun it immediately I would get the result from GetCharacterInfo. I tried Canvas.ForceUpdateCanvases(); but it did not help.

avatar image alifaris · Apr 21, 2017 at 04:34 PM 0
Share

I have the same problem. But I noticed If I stop unity and then rerun it immediately I would get the result from GetCharacterInfo. I tried Canvas.ForceUpdateCanvases(); but it did not help.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

31 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

Related Questions

Text Mesh Pro no outline settings on costume font 0 Answers

Implicit casting scriptable object to font in unity editor 0 Answers

Font Support 0 Answers

Why font does not get enough characters when typing machine , but getting enough to copy and paste this characters! 0 Answers

How to load font into variable 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