Author Topic: [BUG] Animating UIPanelAlpha sets incorrect alpha for UIButton's tweentarget  (Read 6456 times)

cragganmore

  • Guest
I apologize upfront if this is a known issue.  I couldn't find anything about it on the forums.  Also, similar apologies if this is user-error and not really a bug.  I just started working with Unity/NGUI a couple days ago, and I'm not all that familiar with the codebase yet.

So here's what's happening:

I've got a standard UI Root (2D), created with NGUI's create new UI tool.  I've attached a button to the default panel (using the widget tool).  So far, everything works great.

Then I attach a UIPanelAlpha script to the panel.  I add an animation component to the panel, and animate UIPanelAlpha's alpha value from 0 to 1, starting at frame 0 and ending at frame 120.

When I run the project, the panel fades in as expected.  However, the button is getting screwed up.  Specifically, it's turning invisible whenever it's not being clicked or hovered over.  See attached screen shots for visuals:

Shot 1: Scene hierarchy
Shot 2: Animation setup
Shot 3: Panel's state after fade-in animation completes
Shot 4: Button after fade-in but before OnHover() triggered
Shot 5: Button when OnHover() triggers
Shot 6: Button after mouse moves away and OnHover() ends / button returns to normal state / background sprite invisible

When seems to be happening: the button's Init() is getting called for the first time while UIPanelAlpha's UpdateAlpha() method is still iterating the alpha of the panel and its widgets.  Init() is setting the button's mColor alpha to whatever alpha value UpdateAlpha() is on at the time, since mColor is being set to widget.color (which is being modified by UpdateAlpha()).  For example, as UpdateAlpha() is changing the alpha from 0 to 1, when the alpha is at 0.1, the button's Init() gets called and sets its alpha to 0.1.  I'm not sure what's triggering Init() - maybe when UIPanelAlpha disables all the colliders at the beginning, the change to the collider on UIButton is triggering its Init()?  Anyway, this is only a problem when fading in a panel with a button that's never been Init()'d.

My best guess is that, when UIPanelAlpha is done, it needs to set the alphas of all the panel's widgets back to their original values.  I made a cursory try at this, but couldn't get it to work.  Probably something to do with my own ignorance.  :)

Thanks for making such a great API.  It's a joy to use.

Jon

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Try replacing UIButton and UIButtonColor with these two:

cragganmore

  • Guest
Brilliant!  Everything's working perfectly now.

gregmax17

  • Guest
I am running into this issue as well (kind of). I updated the files and it seems to be working just fine for the most part.

However, when I set the alpha property to 1, the button(s) are set to the disabled color (grey). Once in a while it will be set to the proper color (white).

Is there something I am overlooking or not setting that is causing this small head scratcher? I am using iTween to set the float value from 0 to 1, but that should be ok right?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
What are you tweening with iTween, and any reason you're not using the built-in tweening? It's meant to work with NGUI properly.

gregmax17

  • Guest
I am using PlayMaker (sorry, should've mentioned this earlier).

In PlayMaker, I have a action that called "Ease Float". I am storing the result float into a variable and setting the property of the "UIPanelAlpha" alpha through the "Set Property" action. The end result still comes out to be 1.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
UIPanelAlpha.alpha is a public variable, not a property. Other than that, I can't help you much as I am not familiar with Playmaker. Perhaps try asking on their forums?