Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Morgan · May 12, 2015 at 09:12 PM · uicharacterfont

Getting width of word in new UI system: GetCharacterInfo?

I need to get the rendered width of a word (InputField or Text object) in the new UI system (4.6), to implement my own word-wrapping system. (Aside: the built in system will split a long word in the middle if it has to, but I want to shrink the font instead.)

The first two lines of my code (JavaScript/UnityScript) run without error. The third line is the problem:

 var ci : CharacterInfo;
 dotFont.GetCharacterInfo( "T"[0], ci, 32 ); //Font size 32
 Debug.Log (ci.advance);

I want it to tell me the rendered width of a capital letter "T" at 32-point size. (dotFont is assigned in the Inspector, and renders fine visually.)

But I get this error: BCE0019: 'advance' is not a member of 'UnityEngine.CharacterInfo'.

Same error if I try "glyphWidth" instead of "advance". But those are all listed here:

http://docs.unity3d.com/ScriptReference/CharacterInfo.html

What might I be doing wrong? How can I access CharacterInfo details properly from JavaScript? (Or is there a better approach to getting the width of a word? My last resort will be to measure the characters in Photoshop and make my own LUT. Yuck!)

Thanks in advance! (No pun intended.)

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 steakpinball · May 12, 2015 at 09:30 PM 0
Share

What version of Unity are you using?

avatar image Morgan · May 12, 2015 at 10:31 PM 0
Share

Sorry--edited to add that little detail! I'm in 4.6 Pro. (Approaching 5 with caution.)

1 Reply

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

Answer by steakpinball · May 13, 2015 at 01:46 PM

Use CharacterInfo.width instead. CharacterInfo.advance was added in Unity 5 to replace width. It isn't available in 4.6. The properties available in 4.6 are flipped, index, size, style, uv, vert, and width.

http://docs.unity3d.com/462/Documentation/ScriptReference/CharacterInfo.html


You can always find the documentation for your version of Unity installed on you computer. Click the little book icon on any component to open it. (Tip 6 on the tips post)

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 Morgan · May 16, 2015 at 02:49 AM 0
Share

Thanks! .width is indeed accepted without error. (Nice to know about adding 462/Documentation/ to the docs path, too.)

However, it always returns a width of 0 for any character at any font size.

I notice the documentation for Font talks only about GUI Text and Text $$anonymous$$eshes and textures. No mention of the new 4.6 UI system. Is word/character width measurement even possible with the new system (Text and InputField elements)?

(I'll start a new question since I can't re-activate this one.)

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

20 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

Related Questions

Font probem - extended characters 2 Answers

How to Get a Char from his name ? 1 Answer

Getting width of a character in new 4.6 UI system? 0 Answers

Font issues - can someone explain the steps to make a custom font work properly? 0 Answers

Fixed text spacing 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