Support => NGUI 3 Support => Topic started by: juharkonen on October 22, 2013, 07:47:52 AM
Title: UIToggle handler must be a member of a behaviour type
Post by: juharkonen on October 22, 2013, 07:47:52 AM
As I didn't find related posts using the search feature, I wanted to drop a note here for future reference should someone run into the same issue (that is, I'm not requesting help but rather just pointing out an undocumented implicit constraint with the current EventDelegate implementation).
My UIToggle handler delegates weren't getting invoked when I switched toggle button states. I used a utility method like this that hid the static UIToggle.current.value from the handler:
where Notification<bool> inputs a bool and returns void.
The code above creates an anonymous delegate to be subscribed for onChange. However EventDelegate.Set initializes the handler target as
mTarget = call.Targetas MonoBehaviour;
As the handler is an anonymous delegate and not a member of a derived MonoBehaviour, mTarget gets a null value. This causes the EventDelegate.isValid property to return false, and the handler won't be invoked.
I wonder if this is a necessary limitation; the only place where mTarget appears to be used as MonoBehaviour is in the EventDelegate.isEnabled property. This, however, is not used by NGUI.
Title: Re: UIToggle handler must be a member of a behaviour type
Post by: ArenMook on October 22, 2013, 07:53:00 PM
Yes, this has been reported before. You can't use anonymous delegates right now.
Title: Re: UIToggle handler must be a member of a behaviour type
Post by: ArenMook on October 25, 2013, 12:56:28 AM
Update: the latest 3.0.3 allows you to use anonymous delegates: