Author Topic: New UIButton state bug  (Read 5165 times)

Clicker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
New UIButton state bug
« on: March 04, 2014, 09:26:17 AM »
Hello. After updating to NGUI 3.5.3 I have noticed that if I change the button state from script to, for instance, a disabled one and then I make the button SetActive(false) and after returning it to enabled state I get a normal sprite state(not the disabled one) with disabled collider. After reading the scripts, I could find a way to fix it http://clip2net.com/s/6WHqnb. It works good for now, but I am wondering if it is the best way to overcome this issue?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: New UIButton state bug
« Reply #1 on: March 05, 2014, 07:49:59 AM »
Why does commenting out the early exit condition address this particular issue? The button should already be in the same state, so repeated calls to the same state shouldn't have any effect. Can you give more details on what you're doing that causes the problem to appear?

Clicker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: New UIButton state bug
« Reply #2 on: March 05, 2014, 11:53:09 AM »
I guess, you can simply repeat it by following next steps in runtime:
1. Mark a button as disabled from a script;
2. Disable the button game object;
3. Enable the button game object;
4. See the button state (color of the background sprite and enabled state of the collider).
In my case, the color of the button is not correct after doing the steps.

noony

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: New UIButton state bug
« Reply #3 on: March 06, 2014, 09:47:12 AM »
I've encountered this bug in 3.5.3 as well. As far as I can tell, the reason for it is that when the button's GameObject is disabled, the value of its TweenColor is set back to its default color (UIButtonColor.cs:161); this is then applied to the inactive widget (TweenColor.cs:54). Because the Tween is skipped if there is no state change, the button therefore retains its default color despite being in a disabled state.

I haven't found a workaround that doesn't involve reapplying the Tween on every state change as Clicker has.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: New UIButton state bug
« Reply #4 on: March 06, 2014, 10:54:42 AM »
Hmm... well if that's what it's caused by, wouldn't changing UIButtonColor.OnDisable function to the following do the trick?
  1.         protected virtual void OnDisable ()
  2.         {
  3. #if UNITY_EDITOR
  4.                 if (!Application.isPlaying) return;
  5. #endif
  6.                 if (mInitDone && tweenTarget != null)
  7.                 {
  8.                         SetState(State.Normal, true); // <-- this right here
  9.  
  10.                         TweenColor tc = tweenTarget.GetComponent<TweenColor>();
  11.  
  12.                         if (tc != null)
  13.                         {
  14.                                 tc.value = mColor;
  15.                                 tc.enabled = false;
  16.                         }
  17.                 }
  18.         }

noony

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: New UIButton state bug
« Reply #5 on: March 06, 2014, 12:04:05 PM »
That seems to do the trick too, it means the TweenColor state and the collider state are resynchronised when the GameObject is re-enabled.

Thanks for your reply :D