Author Topic: Strange behavior when disabling and enabling widgets at a same frame.  (Read 12299 times)

J. Park

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: Strange behavior when disabling and enabling widgets at a same frame.
« Reply #15 on: June 27, 2012, 08:30:58 PM »
I sent email with sample unity package and video showing my problems.
Please look at them.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Strange behavior when disabling and enabling widgets at a same frame.
« Reply #16 on: June 27, 2012, 08:42:52 PM »
Why are you deactivating and then activating a hierarchy of gameobjects in the same cycle?  What is this attempting to accomplish?

J. Park

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: Strange behavior when disabling and enabling widgets at a same frame.
« Reply #17 on: June 27, 2012, 08:56:45 PM »
There is a situation like this...
When there are many buttons in a scene. I want only some of them to be visible (or active) at the moment.
For convenience, I deactivate all the buttons first (to avoid checking whether each button is active or not), and reactivate some of them needed at that moment.
It should not make problem if I don't use coroutine.
Most unity gameobjects work fine so far.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Strange behavior when disabling and enabling widgets at a same frame.
« Reply #18 on: June 27, 2012, 08:57:52 PM »
You can also just deactivate selectively. Simple equality check will tell you whether it's the button you should be activating or deactivating.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Strange behavior when disabling and enabling widgets at a same frame.
« Reply #19 on: June 27, 2012, 09:03:00 PM »
Seems like a lot of extra work on the part of the engine.  Why not create a Hashtable with the gameobject.name of each button as a key and a bool value of the current state of the button?  Do a compare to see whether or not the current button is active or inactive, and only call SetActive if you actually need to.  You can keep a reference to all of your actual button gameobjects in another hashtable that is likewise referenced by gameobject.name.

You can actually sweep up all of this functionality into one button manager that keeps a static table/collection/array and only have to call one class for all the methods for any button if you know its name.

I imagine all you'd have to do to convince yourself this is a good idea would be to use high resolution timers to compare the number of cycles it takes to do the compares against efficient variable tracking versus tons of recursive object calls.


(Edit:  I guess I just said what Aren said in the post above, just with ten times as many words!)
« Last Edit: June 27, 2012, 09:04:43 PM by JRoch »

J. Park

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: Strange behavior when disabling and enabling widgets at a same frame.
« Reply #20 on: June 27, 2012, 09:40:23 PM »
OK, you may be right.
But I think that's just matter of choice. Everyone has his own coding style.
I can add some codes to check every buttons' state, and it will definately solve that problem.
Or I can walk around the problem by changing position of buttons instead of using SetActiveRecursively.

What I wanna know is not a solution, but reason why ngui widget behave like that to prevent unpredictable mistake in my future work.
« Last Edit: June 27, 2012, 09:45:55 PM by J. Park »

Asse

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Strange behavior when disabling and enabling widgets at a same frame.
« Reply #21 on: August 02, 2012, 10:20:23 AM »
Same problem here, also on Android devices.

Any new insights on this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Strange behavior when disabling and enabling widgets at a same frame.
« Reply #22 on: August 02, 2012, 11:33:07 AM »
I don't remember what the resolution was. What problem are you having / what version are you using?

Asse

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Strange behavior when disabling and enabling widgets at a same frame.
« Reply #23 on: August 03, 2012, 03:00:51 AM »
The problem is that when I activate one object (in my case it's a button) and deactivate another one and both are at the same position, you can see a blink as if the one button gets deactivated immidiately and the other one is activated the next frame. The behavior is visible using SetActiveRecursively or using NGUITools.

I've already played around with the depth, setting both the same or one below, it doesn't change anything.

Oh, and I use version 2.1.0.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Strange behavior when disabling and enabling widgets at a same frame.
« Reply #24 on: August 03, 2012, 05:17:21 PM »
Oh that. First of all, I'd advise grabbing the latest version. After that call UIPanel.Refresh() after enabling/disabling your widgets.

Asse

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Strange behavior when disabling and enabling widgets at a same frame.
« Reply #25 on: August 05, 2012, 06:20:18 AM »
Works like a charm, thanks!