Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Vesuvian on December 04, 2013, 06:58:59 PM

Title: Couldn't bind to method 'OnSelectionChange'
Post by: Vesuvian on December 04, 2013, 06:58:59 PM
NGUI 3.0.4
Unity Pro 4.2.1f

Hi

We are trying to connect via delegate to the OnSelectionChange event in the UIPopupList.

We get the following exception:

  1. ArgumentException: Couldn't bind to method 'OnSelectionChange'.
  2. System.Delegate.GetCandidateMethod (System.Type type, System.Type target, System.String method, BindingFlags bflags, Boolean ignoreCase, Boolean throwOnBindFailure) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System/Delegate.cs:351)
  3. System.Delegate.CreateDelegate (System.Type type, System.Object target, System.String method, Boolean ignoreCase, Boolean throwOnBindFailure) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System/Delegate.cs:397)
  4. System.Delegate.CreateDelegate (System.Type type, System.Object target, System.String method, Boolean ignoreCase) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System/Delegate.cs:406)
  5. System.Delegate.CreateDelegate (System.Type type, System.Object target, System.String method) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System/Delegate.cs:300)
  6. EventDelegate.Get () (at Assets/NGUI/Scripts/Internal/EventDelegate.cs:143)
  7. EventDelegate.Execute () (at Assets/NGUI/Scripts/Internal/EventDelegate.cs:205)
  8. EventDelegate.Execute (System.Collections.Generic.List`1 list) (at Assets/NGUI/Scripts/Internal/EventDelegate.cs:267)
  9. UIPopupList.set_value (System.String value) (at Assets/NGUI/Scripts/Interaction/UIPopupList.cs:204)

I have stripped the project down to the scene/scripts that result in the error:

edit: removed NGUI from the project
www.thisishydra.com/UnityProject.rar (http://www.thisishydra.com/UnityProject.rar)

Please let me know if there is anything we can do to resolve or work around this issue.

Thanks,
Ves
Title: Re: Couldn't bind to method 'OnSelectionChange'
Post by: Darkmax on December 04, 2013, 08:35:53 PM
you need to remove your project link, because it has the code of ngui and you can be banned.

Try to post your code without ngui code, and also try to update to the last version of ngui, maybe is already solve on the last version of ngui.

Also I saw your project, and I didn't see your UIRoot and camera that every project with ngui need, to create those you need to click on NGUI menu/open/ui wizard.  Then on the window, select the layer and gui 2d and click create.

This will generate a UIRoot->Camera->Anchor->Panel, now this where your UI goes. Move add your panel as child of the anchor, and disable your test gameObject and check if this resolves your issues.
Title: Re: Couldn't bind to method 'OnSelectionChange'
Post by: Vesuvian on December 04, 2013, 10:45:48 PM
Thanks Darkmax

Didn't even occur to me to remove NGUI, sorry about that. Were you able to reproduce the issue?

We are definitely using UIRoot in our scene, however I removed our menu management classes in stripping the project down to the bug reproduction. The error occurs regardless.

The test game object is a very simple script that instantiates our NGUI panel and creates the view/model instances that go with it. These steps expose the bug.

The issue here is not with the creation of the panel, rather the way the UIPopupList component uses reflection to bind to the OnSelectionChange method.

Unfortunately we are only using standard licenses. Is 3.0.4 no-longer the most recent available version?
Title: Re: Couldn't bind to method 'OnSelectionChange'
Post by: wom on December 05, 2013, 02:41:56 AM
Look in the latest version sticky of the forum for all the release notes for each version - I definitely remember seeing something about a change with delegates recently.  Additionally, that topic as far as I know is pretty definitive for what's the latest version of NGUI.
Title: Re: Couldn't bind to method 'OnSelectionChange'
Post by: Nicki on December 05, 2013, 05:28:35 AM
You use the new one like this:
  1. EventDelegate.Add(theObject.OnChange, CallbackMethod, oneShotBool);

The old one is a legacyEvent, but can be used as a normal delegate until removed.
  1. myPopupList.onSelectionChange += MyDelegateHandler;
Title: Re: Couldn't bind to method 'OnSelectionChange'
Post by: Vesuvian on December 05, 2013, 09:15:17 AM
Thanks for your input guys

I've read the versions thread and it looks like my version of NGUI has all the delegate changes.

I've modified my method to:

  1. // Configures the UIPopupList so we can recieve selection event
  2. private void __setupPopupListEvent(UIPopupList popupList)
  3. {
  4.         EventDelegate eventDelegate = new EventDelegate(this, "OnSelectionChange");
  5.         EventDelegate.Add(popupList.onChange, eventDelegate, false);
  6.        
  7.         //popupList.onChange.Add(eventDelegate);
  8. }

And this still causes the errors. I've reuploaded the project:

www.thisishydra.com/UnityProject%20v2.rar (http://www.thisishydra.com/UnityProject%20v2.rar)
Title: Re: Couldn't bind to method 'OnSelectionChange'
Post by: Nicki on December 05, 2013, 09:20:28 AM
Nono, you shouldn't make an eventdelegate object - it's all static.

  1. private void __setupPopupListEvent(UIPopupList popupList)
  2. {    
  3.     EventDelegate.Add(popupList.onChange, MyMethod, false);
  4. }
  5.  
  6.  
  7. void MyMethod()
  8. {
  9. //...
  10. }
  11.  
Title: Re: Couldn't bind to method 'OnSelectionChange'
Post by: Vesuvian on December 05, 2013, 09:35:46 AM
Thanks a ton Nicki, this seems to have resolved our issues.