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 /
avatar image
0
Question by limez · Nov 15, 2015 at 08:14 AM · unity 5editor-scriptingfontfonts

Building custom Font with script, can not change CharacterInfo

I wanted to make several custom bitmap fonts for my game, and after looking into it I realized that this is a painstaking process to set up in Unity. So I decided to write an editor script to automatically generate the rects for my characters. The problem is, whenever I try to set the CharacterInfo struct inside my fonts, the change doesn't seem to actually happen. Here's the relevant code:

 if(changed) {
     var nci = new CharacterInfo();
     nci.minX = (int)currentRect.xMin;
     nci.maxX = (int)currentRect.xMax;
     nci.minY = (int)currentRect.yMax;
     nci.maxY = (int)currentRect.yMin;
     nci.index = ci.index;
     currentFont.characterInfo[currentChar] = nci;
     Debug.Log(currentFont.characterInfo[currentChar].minX);
 }

After having set the new CharacterInfo struct, the value of the old CharacterInfo is always logged. Is this something new in Unity 5? It seems some things have changed, such as the way the uv and vertex rects are represented, but I don't see how that should affect the behaviour. Is there something else I'm missing?

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 limez · Nov 15, 2015 at 04:13 PM 0
Share

$$anonymous$$y current tentative solution involves using Shoebox with this script, but I have many other reason to want my own editor script to do the same thing. The linked script uses the old UV and verts rects, which are deprecated and throw warnings, so an up-to-date solution would still be nice! However, I am able to proceed with this, albeit with annoying warning.

avatar image Glurth · Nov 15, 2015 at 06:55 PM 0
Share

Total shot in the dark here, but based on similar problems I've had- all those turned out to be accessor vs ACTUAL variables issues. Though the more I think about it, the less I think this is the issue. If the characterInfo array in the font is an accessor into an array, rather than the array itself, you may wish to created an entirely NEW ARRAY, and when all setup, assign THAT to your currentFont.

So, rather than assigning each element individually like this:

 currentFont.characterInfo[currentChar] = nci;

Ins$$anonymous$$d, setup your own local array:

 CharacterInfo[] myCharInfo= new CharacterInfo[currentFont.characterInfo.length];
 ...
 loop
 ....
 myCharInfo[currentChar] = nci;
 ....
 endloop
 ....
 currentFont.characterInfo = myCharInfo



1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by vitorlanna · Jun 15, 2019 at 09:09 PM

Probably not revelant to @limez anymore, but to anyone else who finds this topic in the future - while I wasn't able to solve the problem, setting the characterInfo's array size to 0 in the inspector makes it so you can edit it through script and the changes will stick. Otherwise they reset to a previous logged value like limez said.

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

6 People are following this question.

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

Related Questions

How can you change the font of options in a UI dropdown 1 Answer

Font Render Issue Unity 5.3.4f1 on Samsung devices 1 Answer

Any way to use multiple font styles within a single UI Text component? 1 Answer

Dynamic font with no material turns black after update (sometimes) 1 Answer

Fill Font Characters with White? 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