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 JACLEMGO · Jun 23, 2014 at 10:55 PM · guiiosiphonelagngui

Massive lag due to Font.CacheFontForText. Please help!

I have a massive lag (1128ms) on the Ipad 2, the profiler shows this: alt text

I have already done all the suggestion on the forums: Change font to non dynamic Dont change color from code Dont change size. Also changed the font to Arial, no difference.

Im using NGUI and also 3d Text (TextMesh)

Any other suggestions?

capture.png (125.6 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sschaem · Jun 24, 2014 at 01:09 AM

You can try to create dummy text during your level load time to make sure the dynamic caching does it work then and not at some other importunate times?

If not, you can try "TextMesh Pro", it is optimize to do little to no run-time allocation. Once your font is loaded, you are pretty much guarantied to be alloc free.

And loading a font is also extremely efficient as its using very compact SDF atlas.

Comment
Add comment · Show 5 · 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 JACLEMGO · Jun 24, 2014 at 06:55 AM 0
Share

Text$$anonymous$$esh Pro looks great, just worried that it might not solve my problem, do you have a demo version I can try out first?

avatar image JACLEMGO · Jun 24, 2014 at 01:58 PM 0
Share

Bought the package earlier today, no luck :(

avatar image sschaem · Jun 25, 2014 at 12:41 AM 0
Share

Text$$anonymous$$esh Pro doesnt rely on Font.CacheFontForText, and this should be gone from your profiler report. If not I'm guessing that some object in the scene still rely on the Font class.

You can get in depth tech support at : http://digitalnativestudios.com/forum/

avatar image Stephan-B · Jul 04, 2014 at 10:41 AM 0
Share

@JACLE$$anonymous$$GO: I am the author of Text$$anonymous$$esh Pro and although the Font.CacheFontForText isn't related to Text$$anonymous$$esh Pro, given you purchased my product, I would like to help you out if you still haven't solved your issue. Please feel free to email: support@DigitalNativeStudios.com

avatar image JACLEMGO · Jul 04, 2014 at 10:47 AM 0
Share

@stephanB problem solved, was Unity Dynamic font. Thank you

avatar image
0

Answer by IVxIV · Dec 24, 2014 at 08:37 PM

For anyone else who encounters this same issue, here is another solution you could consider. I ran into the same problem as a result of using custom GUIStyle objects for rendering in my OnGUI calls, some of which referenced custom dynamic fonts (this is the source of the problem - dynamic font glyphs get cached to an internal font cache texture in Unity).

To avoid taking the big hit all at once when Font.CacheFontForText() is first called by means of an OnGUI call, inside an Awake() call for my UI code I spin up a coroutine to asynchronously precache each of my dynamic fonts' glyph data, making repeated calls to Font.RequestCharactersInTexture(). This has worked nicely so far for my relatively simple UI needs, and avoids having one giant blocking stall where the GUI font cache is populated all at once.

Here is some sample code to illustrate the basic approach I used:

 public class GUIClass : MonoBehaviour
 {
     private static readonly string kPrecacheFontGlyphsString= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\\:;\"'<>,.?/ ";
     
     // utility struct used in font caching
     struct CacheFont
     {
         public Font theFont;
         public int size;
         public FontStyle style;
     };
     
     void Awake()
     {
         // gather custom fonts that we will be using
         CacheFont[] myCustomFonts= RetrieveMyCustomFonts();
 
         if (null != myCustomFonts)
         {
             for (int fontIndex= 0; fontIndex < myCustomFonts.Length; ++fontIndex)
             {
                 StartCoroutine(PrecacheFontGlyphs(
                     myCustomFonts[fontIndex].theFont,
                     myCustomFonts[fontIndex].fontSize,
                     myCustomFonts[fontIndex].fontStyle,
                     kPrecacheFontGlyphsString));
             }
         }
         
         return;
     }
 
     // Precache the font glyphs for the given font data.
     // Intended to run asynchronously inside of a coroutine.
     IEnumerator PrecacheFontGlyphs(Font theFont, int fontSize, FontStyle style, string glyphs)
     {
         for (int index= 0; (index < glyphs.Length); ++index)
         {
             theFont.RequestCharactersInTexture(
                 glyphs[index].ToString(),
                 fontSize, style);
             yield return null;
         }
         
         yield break;
     }
 
 
     void OnGUI()
     {
         // now that dynamic font glyphs have been precached,
         // there won’t be a terrible hitch the first time this is called
     }
 };
 
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 wangunity · Dec 26, 2014 at 06:45 AM 0
Share

hello, how to solve a the problem when i use NGUI font ?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

I have problem when i want to using button instead keyboard in iOS 1 Answer

iphone like date pickers 1 Answer

Game works fine on computer but lags on ios device. Please Help! 2 Answers

[NGUI] Sprites breaking on switching from Android 0 Answers

iPhone GUI buttons problem 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