Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: rayark on April 14, 2014, 10:55:54 PM

Title: Scrambled text with UILabel / UIFont of NGUI 3.5.7
Post by: rayark on April 14, 2014, 10:55:54 PM
Hi,

My project suffers from scrambled text with UILabel / UIFont of NGUI 3.5.7.
Scrambled text only appears when running play mode in Unity Editor, and in standalone application, everything is OK.

After debugging,
I found that when running play mode in Unity Editor,
Unity will always create object with default constructor for private fields which class has the attribute [System.Serializable], even if those fields are private.

In UIFont.cs,
  1. public class UIFont : MonoBehaviour
  2. {
  3.     ...
  4.     UISpriteData mSprite = null;
  5.     ...
  6. }
  7.  
because UISpriteData is a pure C# class with the attribute [System.Serializable],
mSprite will be initialized with default constructor when compiled managed DLLs is loaded by UnityEditor.

Therefore, when running play mode in Unity Editor, some initialization logic won'be executed because mSprite is not initialized as null.

(http://www.tasharen.com/forum/index.php?action=dlattach;topic=9092.0;attach=4178)

To fix this problem,
I put attribute [System.NonSerialized] to mSprite, and it won't be initialized with default constructor anymore, and the rendering of UILabel becomes correct.

  1. public class UIFont : MonoBehaviour
  2. {
  3.     ...
  4.     [System.NonSerialized]
  5.     UISpriteData mSprite = null;
  6.     ...
  7. }
  8.  


Alvin
Title: Re: Scrambled text with UILabel / UIFont of NGUI 3.5.7
Post by: ArenMook on April 15, 2014, 09:23:20 AM
I vaguely remember running into this back in Unity 3.4 days, and I've not seen it in years... what version of Unity are you running?
Title: Re: Scrambled text with UILabel / UIFont of NGUI 3.5.7
Post by: rayark on April 15, 2014, 10:24:20 PM
I currently use Unity 4.3.4f1.

Title: Re: Scrambled text with UILabel / UIFont of NGUI 3.5.7
Post by: ArenMook on April 16, 2014, 10:34:05 AM
Interesting... well, I'll add that line, it doesn't do any harm.