- Home /
StartCoroutine("MyMethod", parms) and MissingMethodException: Cannot find method MyMethod
MissingMethodException: Cannot find method MyMethod.
System.MonoType.InvokeMember (System.String name, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object target, System.Object[] args, System.Reflection.ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, System.String[] namedParameters) (at /Applications/buildAgent/work/84669f285f6a667f/mcs/class/corlib/System/MonoType.cs:520)
UnityEngine.SetupCoroutine.InvokeMember (System.Object behaviour, System.String name, System.Object variable)
UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
I'm having this problem when I call my Coroutine. If I remove the "object[]" parameter from the code, or change it to a float parameter (for example) it works fine. . . The strangest thing is that I'm using the exact same approach in another class and there this issue doesn't happen Oo
Heres my code snippet:
public void DoSomething(int someParam, bool temp = false, float tempSeconds = 5f)
{
actualParam = someParam;
StopCoroutine("MyMethod");
object[] parms = new object[2]{temp, tempSeconds};
StartCoroutine("MyMethod", parms);
}
IEnumerator MyMethod(object[] parms)
{
// Do something
yield return new WaitForSeconds(0.1f);
// Do something else after 0.1
if((bool)parms[0] == true)
{
yield return new WaitForSeconds((float)parms[1]);
// Do Something else
DoSomething (actualParam*2);
}
}
*EDIT: Sorry, I forgot to mention that:
I'm now caching the parameters outside the functions so I can get it working OK, but the issue still exists;
I'm using Unity PRO 4.1.5f.
Is this your actual code? Apparently it can enter an endless loop: DoSomething starts coroutine $$anonymous$$y$$anonymous$$ethod, which in turn calls DoSomething, and so on.
I am getting the same issue but only when running on wp8
Answer by SubatomicHero · Jul 01, 2013 at 02:35 PM
You are searching for the coroutine using the string version of the argument. Why don't you call it by passing in the method name directly which is more effecient:
// instead of:
StartCoroutine("MyMethod", parms);
// do this:
StartCoroutine(MyMethod(parms));
Hi!, thank you for your answer. The reason that I'm not using this approach is that I can't Stop my Coroutines.
Please note that only StartCoroutine using a string method name can be stopped using StopCoroutine.
To be honest, you should know when the coroutine will stop or the code inside the coroutine should perform fully and then stop by itself. Are you sure you need a coroutine?