Author Topic: Couldn't bind to method 'OnSelectionChange'  (Read 9980 times)

Vesuvian

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Couldn't bind to method 'OnSelectionChange'
« 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

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

Thanks,
Ves
« Last Edit: December 04, 2013, 10:47:10 PM by Vesuvian »

Darkmax

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 93
    • View Profile
Re: Couldn't bind to method 'OnSelectionChange'
« Reply #1 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.
« Last Edit: December 04, 2013, 08:48:14 PM by Darkmax »

Vesuvian

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: Couldn't bind to method 'OnSelectionChange'
« Reply #2 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?

wom

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Couldn't bind to method 'OnSelectionChange'
« Reply #3 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.
« Last Edit: December 05, 2013, 02:57:43 AM by wom »

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Couldn't bind to method 'OnSelectionChange'
« Reply #4 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;
« Last Edit: December 05, 2013, 05:49:13 AM by Nicki »

Vesuvian

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: Couldn't bind to method 'OnSelectionChange'
« Reply #5 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

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Couldn't bind to method 'OnSelectionChange'
« Reply #6 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.  

Vesuvian

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: Couldn't bind to method 'OnSelectionChange'
« Reply #7 on: December 05, 2013, 09:35:46 AM »
Thanks a ton Nicki, this seems to have resolved our issues.