Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: loopyllama on April 25, 2012, 05:39:20 AM

Title: widgets from firing an event on start
Post by: loopyllama on April 25, 2012, 05:39:20 AM
Perhaps this will just help me understand it a bit better. NGUI has been great for creating visual UI elements.

However I find myself constantly fighting the NGUI design of widgets like UISlider and UICheckbox firing an event on start. For me, it messes up all kinds of things. I write the values to disk and read them in on Awake. I respond to the changes of value on these widgets. This means on Start I get all kinds of events telling me the current value of the widget when in fact I want to be telling the widget what its value is. Because the earliest I can read a value from disk is Awake and I get the unwanted event from the widget in Start, this leaves very little wiggle room. I have to read in the values from disk in awake and I have to set the value of the widget in awake. This means I have to be absolutely sure I am reading the values on disk first, then finding my widget, then setting my widget to the value from disk. Some widgets have extra things I have to call like ForceUpdate. Some do not.

All of this battling, makes it work, but why do I have to battle? What is the case where I would want the widget to send me an event of its value BEFORE the user changes it? After all isn't that what a UI is? A way to get an interaction from the user? Why would I want the widget send me an event when it wakes up? For all of my current cases it only causes me a headaches because I do not want this event, as it is only the widget telling me its value.

Maybe a checkbox on these widgets like doNotFireEventOnStart?
In that case I can read my values from disk in Awake and set the value of the widget in Start, making things so much easier.

Can anyone else chime in? Am I doing something wrong or do you also  find yourself battling the fired event on start?
Title: Re: widgets from firing an event on start
Post by: ArenMook on April 25, 2012, 11:28:01 AM
Just place your init code in Awake() as well. You can set up script execution order in such a way that your disk-reading script is executed before others, thus ensuring that its data is present when others call its Awake() function.