Author Topic: Bitmap Font + Prefab Problem  (Read 18562 times)

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Bitmap Font + Prefab Problem
« on: February 03, 2015, 10:36:52 AM »
Hi,
We have the last version of NGUI (just downloaded it).
We have created Bitmap Font from Unity font using Font Maker in size 40 (Arial Bold).
We are then using the font in many labels in the app, including in prefabs instantiated at runtime.
When we set the font in UILabel, it prints 21 as fontSize and 40 as defaultSize.
But when we instantiate the prefab, it prints 21 as fontSize and 21 as defaultSize but the font is displayed on screen at size 40.
If I change the fontSize in the editor just by one size during runtime, (say 22), defaultSize goes back to 40 and the label is displayed at the right size(22).

I tried to do a hack by doing label.fontSize = label.fontSize but your setter is checking if the fontSize changed, and I'm affraid of killing perfs if I change this behaviour.

Before we were using dynamic font but Dynamic Font Arial is very buggy on Android, so we changed all the labels using Arial and Dynamic Font by Bitmap but it's now worse than before with this bug.

Can you help us?
« Last Edit: February 03, 2015, 10:43:54 AM by r.pedra »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bitmap Font + Prefab Problem
« Reply #1 on: February 03, 2015, 11:08:36 AM »
What is it you're checking, exactly? Inspector, or in code? UILabel.defaultSize simply forwards the request to UIFont.defaultSize, which in turn will give you mFont.charSize. Where does the value differ for you? Also, I am assuming you are instanting a label here when you say that you're instantiating a prefab. I hope you aren't trying to instantiate a font.

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: Bitmap Font + Prefab Problem
« Reply #2 on: February 03, 2015, 11:16:04 AM »
Aren, people trying to instantiate fonts really exists? I thought it was a legend  :P

Say I have a prefab structured with different GameObjects and Widgets.
Some of these Widgets are UILabel.
When I'm settings these UILabel, i give them UIFont(so bitmap), created from Font, and i have set their size to 40 in FontMaker.
At this time everything is correct in the UILabel, defaultSize is 40, and fontSize is 21 (because I needed 21 in this case).

I save my prefab.

Then I instantiate it at runtime, and SURPRISE, my label is displayed supersized, so I check the UILabel settings in Inspector and it says this :
fontSize: 21
defaultSize: 21

This is not even coherent with the size of the label displayed in the app.
So I entered a different number in fontSize in the editor, say 22.
The defaultSize changed immediatly to 40 and in the app, the label is displayed normally (not super sized anymore).

Do you understand? I can make screenshots if you want

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bitmap Font + Prefab Problem
« Reply #3 on: February 03, 2015, 11:47:19 AM »
It might be best if you created a simple repro case for me so I can have a look.

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: Bitmap Font + Prefab Problem
« Reply #4 on: February 03, 2015, 12:06:42 PM »
I just tried to create a basic repro case but the problem doesn't occurs. But when I use all the prefab that have this problem in my other scene, the problem occurs.
It doesn't occurs if I delete some parts of the prefab. I need to investigate more.

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: Bitmap Font + Prefab Problem
« Reply #5 on: February 04, 2015, 05:55:10 AM »
Hi, we made a funny discover.
We are debugging UILabel.trueTypeFont and UILabel.bitmapFont at Start, and for UILabel already in the scene, trueTypeFont is NULL and bitmapFont is not.
But when we instantiate prefabs containing UILabel, trueTypeFont contains default Arial(that was the first settings of the UILabel, before we switched to bitmapFont), and bitmapFont contains our new bitmapFont.

Is that a normal behaviour?

EDIT:
We tried the following code:
  1. if(label.trueTypeFont != null && label.bitmapFont != null){
  2.                                 label.trueTypeFont = null;
  3.                                 label.SetDirty();
  4.                         }

But UILabel doesn't display anymore, and it says in Inspector that Font is empty even if label.bitmapFont is not empty.
We saw that when you set trueTypeFont to NULL it switches mFont to NULL, so we added label.bitmapFont = label.bitmapFont before SetDirty but it also doesn't work.

EDIT2:
We finally find a workaround.
Executing this on labels:
  1. if(label.trueTypeFont != null && label.bitmapFont != null){
  2.         label.bitmapFont = label.bitmapFont;
  3.         label.SetDirty();
  4. }

And deleting the condition in UILabel line 179
« Last Edit: February 04, 2015, 06:15:56 AM by r.pedra »

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: Bitmap Font + Prefab Problem
« Reply #6 on: February 04, 2015, 06:31:43 AM »
Another weird bug. If I close Unity or if I compile, the UIFont is totally fucked up, if I regenerate the font it works, but if I compile or close the editor, UIFont is again fucked up.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bitmap Font + Prefab Problem
« Reply #7 on: February 05, 2015, 10:10:52 AM »
Sounds like you created the font prefab using Arial originally, then later changed it to a bitmap font without the reference being cleared. Perhaps some old version of NGUI? I suggest recreating the font.

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: Bitmap Font + Prefab Problem
« Reply #8 on: February 05, 2015, 10:29:24 AM »
We started the project last year in January, so we began with a very old version ahah.
But it's weird that when you change Dynamic Font by Bitmap Font the old reference is not cleared.
Moreover I made the change after I upgraded to the last version.

For the second problem mixing all the characters, we didn't find another solution than generate atlas outside of Unity with bmGlyph, but this is a really annoying problem.