Author Topic: bug with UILabel effects  (Read 6237 times)

Gillissie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
bug with UILabel effects
« on: June 26, 2012, 12:25:14 AM »
Hello,

I noticed something that appears to be a bug. I have a UILabel with the Shadow effect defined. It looks correct in the editor at design time. When I instantiate the prefab that has the label, I immediately set the localScale to Vector3.zero to hide the label until after some other stuff happens, then I call MakePixelPerfect() to show the label. However, when I do this, the shadow effect is not visible. The properties on the UILabel show it set to Shadow and the color set as expected, but the effect isn't there. If I change the color or the effect style, it seems to fix it. As a workaround I am changing the style in code to None then back to Shadow after calling MakePixelPerfect().

Gillissie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
Re: bug with UILabel effects
« Reply #1 on: June 26, 2012, 12:59:45 AM »
I noticed a similar issue with the label not showing anything unless I disable and re-enable the UILabel script.

Gillissie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
Re: bug with UILabel effects
« Reply #2 on: June 26, 2012, 11:43:29 AM »
Another related issue. If I set the scale to .001, .001, .001 instead of zero, the label appears when I set it back to 1,1,1 but it is offset in a strange way. If I change the scale on the label it fixes itself.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: bug with UILabel effects
« Reply #3 on: June 26, 2012, 04:47:35 PM »
Setting the scale to 0 causes a division by zero error when trying to calculate the inverse transform. Don't do it. Why don't you just instantiate the label with it being transparent instead? Same invisible effect, but won't involve messing with the scale.

Gillissie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
Re: bug with UILabel effects
« Reply #4 on: June 27, 2012, 01:02:17 AM »
I'm not actually setting the scale of the label directly. It's a child object, along with other child objects, and the parent is being set to 0 to hide everything under it. Also, I avoided using SetActiveRecursively(false) because the parent object above that one needs to be set active before all of the children do, so that's just a mess. I'm just not sure why MakePixelPerfect() doesn't do the fix automatically as part of that. It appears that it's trying to optimize by not doing anything if it thinks there is nothing to do, even though it would benefit from rebuilding.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: bug with UILabel effects
« Reply #5 on: June 27, 2012, 01:41:39 AM »
So put in some kind of initialization delay, or just call methods between the objects directly if you need to control activation steps.  If deactivating a branch of the gameobject hierarchy breaks things, then you likely have approached your solution in a... sub-optimal... way.

I've spent the last couple days breaking my brain around NGUI, and Unity, and have found that I could rip out large sections of code I wrote just the day before and replace them with smaller, simpler logic that suddenly seemed obvious.  Sometimes it takes a while to start to grasp the implicit class-object relationship between scripts and gameobjects.

This is just a long way round of saying:  setting a scale transform to zero sounds really silly when you could likely just translate it out of the scene far enough that it's out of camera range.  But, honestly, SetActiveRecursively is likely the best way to handle it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: bug with UILabel effects
« Reply #6 on: June 27, 2012, 06:41:34 AM »
Use NGUITools.SetActive instead of SetActiveRecursively. The NGUI method actually enables and disables them in a proper order.

That said, it doesn't matter whether the label's scale is 0 or its parent, a zero is still a zero -- and you still get the division by zero issue. As I said, just don't do it.