Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by demented_hedgehog · Sep 15, 2015 at 06:55 AM · fontlayoutspacing

Get CharacterInfo in the Editor?

I'm trying to lay out some text in a MonoBehaviour script. Now the font knows its name "Arial" and its size 13 but when I do this:

 CharacterInfo info;
 foreach (char c in text) {
     font.GetCharacterInfo (c, out info);
     Debug.Log ("Char is [" + c.ToString() + "]: " + info.advance.ToString("F6"));
 }

GetCharacterInfo is returning False and I get this output:

 Char is [T]: 0.000000
 Char is [h]: 0.000000
 Char is [e]: 0.000000
 Char is [ ]: 0.000000

So my questions are: "Why is this so?", and "What can I do to get this information?"

Note that the monobehaviour has the [ExececuteInEditor] flag set although it doesn't work when I play the game either. Also in Unity 5.2.0f3 on wine if that matters.

Comment
Add comment · Show 2
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 demented_hedgehog · Sep 15, 2015 at 07:04 AM 0
Share

Possibly a long term problem .. see post at the end http://forum.unity3d.com/threads/font-getcharacterinfo-bug-in-wp8-win8-for-non-latin-character.200570/

avatar image demented_hedgehog · Sep 15, 2015 at 07:29 AM 0
Share

Looks like a duplicate of this one: http://answers.unity3d.com/questions/967826/getting-width-of-a-character-in-new-46-ui-system.html

No one has answered except for $$anonymous$$organs stop gap solution :(

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by demented_hedgehog · Sep 18, 2015 at 11:07 AM

OK.. user error here. There's a mismatch between the fontsizes. I don't know where the font size of 13 is coming from but if I change the font size in GetCharacterInfo to 14 which is the font size of the UI.Text field I get non zero values for advance.

More info. Areas of confusion.

1) Font has a fontSize. UI.Text has a fontSize and a font. Setting a UI.Text instances font does not set the UI.Texts fontSize to the fonts fontSize!

2) Had I RTFM then I would have noticed that before the character info is available you have to call RequestCharactersInTexture(...) to make sure that the character info is included. See http://docs.unity3d.com/ScriptReference/Font.RequestCharactersInTexture.html

Comment
Add comment · Show 1 · 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 ZpeedTube · Nov 22, 2016 at 12:38 PM 0
Share

Thnx!

Font.RequestCharactersInTexture(string, fontsize);

Was exactly what I needed! :)

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

28 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

Related Questions

How do I space out UI elements evenly in a horizontal layout group? 1 Answer

Problem with dynamic height elements inside Vertical Layout Group 0 Answers

Ui layout elements keep reverting after taken outside of grid element 0 Answers

Issues with layout after building 0 Answers

How to make child of layout group always fit the screen size and be placed side by side? 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