The problem I’m facing is that I’m getting an error when creating said delegate.
It’s telling me that the arguments are incompatible.
ArgumentException: method arguments are incompatible
System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, System.Boolean throwOnBindFailure, System.Boolean allowClosed) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method, System.Boolean throwOnBindFailure) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method) (at <9577ac7a62ef43179789031239ba8798>:0)
EventCatcher.Start () (at Assets/EventCatcher.cs:48)
What I don’t understand is that the arguments seem to be aligned. The following is the declaration of the function I want to call, the declaration of the delegate and the creation of the delegate.
public void __Attack_SetFocused() // this is the function I want to call. (In file A)
public delegate void OnClickFunction(); // this is the declaration of the delegate (In file B)
OnClickFunction onClickFunction; // this is the variable I create (in file B)
The assignment of the delegate is below:
System.Type inf = typeof(ButtonBehaviors);
foreach (var method in inf.GetMethods())
{
if (method.Name == "__Attack_SetFocused")
{
onClickFunction = (OnClickFunction)System.Delegate.CreateDelegate(typeof(OnClickFunction), method);
}
}
Clearly I’m not interpreting the error correctly. If anyone can help me figure this out, I’d appreciate it.