ArgumentException: method return type is incompatible

I’m sending an integer via a UI button event in 4.6 to this (simplified) function and it’s giving me a runtime error. Any ideas what I’m doing wrong?

public IEnumerator ChangeScreen ( int newScreen )
	{
		yield return null;
	}

Full error looks like this:

ArgumentException: method return type is incompatible
System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Delegate.cs:190)
System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Delegate.cs:276)
UnityEngine.Events.InvokableCall1[System.Int32]..ctor (System.Object target, System.Reflection.MethodInfo theFunction) UnityEngine.Events.CachedInvokableCall1[System.Int32]…ctor (UnityEngine.Object target, System.Reflection.MethodInfo theFunction, Int32 argument)
UnityEngine.Events.PersistentCall.GetRuntimeCall (UnityEngine.Events.UnityEventBase theEvent)
UnityEngine.Events.PersistentCallGroup.Initialize (UnityEngine.Events.InvokableCallList invokableList, UnityEngine.Events.UnityEventBase unityEventBase)
UnityEngine.Events.UnityEventBase.RebuildPersistentCallsIfNeeded ()
UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters)
UnityEngine.Events.UnityEvent.Invoke ()
UnityEngine.UI.Button.Press () (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/UI/Core/Button.cs:36)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/UI/Core/Button.cs:45)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/ExecuteEvents.cs:52)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/ExecuteEvents.cs:269)
UnityEngine.EventSystems.EventSystem:Update()

i have a solution of the yield Problem. Unity Version 4.6.1

public IEnumerator ChangeScreen ( int newScreen )
{
test();

}

function test() {
yield return null;
}

I think it is because I have set the function to be IEnumerator and the event system can only call non-returnable functions.

It’s a bit of a bug. An IEnumerator method won’t show up as a possible choice in the event properties, but if you begin it as void, select it in the event list, then change its type in the script later, it’ll still be chosen in the event properties and that’s when you start getting errors.