• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by BurnedZombie · Jun 08, 2016 at 03:50 PM · eventreflectiondelegateevent-handling

Delegate.CreateDelegate fail to call correct overloaded function..

im try to make (C# - WinForm like) Style Editor UI System. so new EditorWindow("MethodHaveClass") is going to make at runtime(exactly, this class is inherited UnityEditor.EditorWindow class.) . then Controls ("EventHaveClass") added on EditorWindow. in this case. i think i need this reflection code.. to use added controls.. here is the code

[CODE] public class MethodHaveClass() :EditorWindow { public static void ClickEventTest() { Debug.Log("Clicked!!"); }

public class EventHaveClass() { public delegate void CustomEvent(); public event CustomEvent OnClicked; }

public class ButtonControl : EventHaveClass() { public void Init(string methodClassName, string methodName, string eventClassName string eventName) { Type methodClassType = Type.GetType(methodClassName); MethodInfo m_Info = methodClassType.GetMethod(methodName);

Type eventClassType = Type.GetType(eventClassName); EventInfo m_event = eventClassType.GetEvent(eventName);

Delegate handler = Delegate.CreateDelegate(m_event.EventHandlerType, m_Info); // <- exception m_event.AddEventHandler(eventClassType, handler); } } [/CODE] and Delegate.CreateDelegate function makes exception below.


ArgumentException: method argument length mismatch System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Delegate.cs:226) ButtonControl.Init (System.String id, System.String windowName, Rect rect, System.String controlName, System.String LClick, System.String RClick, System.String texturePath) (at Assets/Editor/CustomEditor/Controls/ButtonControl.cs:48) UnityEditor.GenericMenu.CatchMenu (System.Object userData, System.String[] options, Int32 selected) (at C:/buildslave/unity/build/artifacts/generated/common/editor/GenericMenuBindings.gen.cs:122)


i want to use CreateDelegate(Type, MethodInfo) this type of overload method but in exception message says "CreateDelegate(Type, Object, MethodInfo, Boolean) " with ArgumentException: method argument length mismatch. exception. how can i fix it? or Something wrong Delegate.CreateDelegate function with Unity 5.3.4f1?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Event NullReferenceException 1 Answer

Delegates & Events registration & deregistration - Doubt 0 Answers

Question regarding delegates and events 1 Answer

Instance variables and this == null in event handler 1 Answer

How to call function on AssetDatabase.importPackageCompleted 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges