Author Topic: UIButton init bug  (Read 4678 times)

pengyingh

  • Guest
UIButton init bug
« on: March 05, 2013, 12:30:24 AM »
 :)NGUI of new version have a bug:
      1. I init a button 's attribute - 'isEnabled' to false by default on Start() func
      2. When i set the button isEnabled = true, and the button 's background 's alpha turn to 0.
previous version had no this bug, I check the UIButtonColor class,
replace the code in Start Func to Awake (),  fixed this.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton init bug
« Reply #1 on: March 05, 2013, 12:40:15 PM »
I think it's a better option to add this to UIButton.UpdateColor:
  1. if (!mStarted)
  2. {
  3.         Init();
  4.         mStarted = true;
  5. }

silversteez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
    • MattSilverstein.com
Re: UIButton init bug
« Reply #2 on: March 08, 2013, 04:51:34 PM »
i'm not sure if this is related, but since the latest update of NGUI i have a new button bug (sounds like it's probably related somehow...).

pretty simple - if i set a button to isEnabled = true at runtime, the color does not update. it remains grey.

if i save the button state as isEnabled = true (via playerprefs) and then start a new game session it will be the proper color.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton init bug
« Reply #3 on: March 08, 2013, 08:47:44 PM »
Not sure what you're asking. If the button's isEnabled state is false, its color won't update because the collider is disabled so there is nothing to receive events. That's how it should be.

silversteez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
    • MattSilverstein.com
Re: UIButton init bug
« Reply #4 on: March 09, 2013, 09:31:59 PM »
the button's isEnabled state is false when the game loads. if i set the isEnabled state to true while the game is running (the player unlocks the next level, etc) then the button's collider becomes active and it is functional, but the color is still grey. if i quit the game and start again the button will be the correct color.

only been happening since 2.3.4, but if no one else is having this problem then i'll just assume it's something on my end.

silversteez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
    • MattSilverstein.com
Re: UIButton init bug
« Reply #5 on: March 11, 2013, 01:55:58 PM »
I figured out what was causing the problem and I'll post it here in case anyone else has the same issue.

I was setting this particular UIButton's isEnabled state to 'false' in my gameManager's Awake() method if the player had not previously unlocked a corresponding level in the game. Once I placed this code (which checks the player's PlayerPrefs to see if they had already unlocked the level, etc, and then sets the isEnabled state of the button) in my gameManager's Start() method everything worked just fine again.

Using the Awake() method was working fine prior to 2.3.4, so I'm guessing something minor changed in the how/when of UIButton's code for storing the enabled color of a button before setting isEnabled to false.

I probably should have been using Start(), anyway. It takes awhile learning Unity to really figure out when to use Awake(), Start(), OnEnable(), etc...