Extend StartCoroutine

I’ve searched UnityAnswers, and google, and haven’t found a solution to extending the EXPLICIT StartCoroutine method. I’m speaking specifically of the String-based startcoroutine method, that ONLY allows for one(1) parameter to be passed to it, called as follows:

StartCoroutine(“NameOfCoRoutineHere”, ParameterToPassHere);

If its possible, I need to be able to explicitly call a CoRoutine, using the string naming convention, with the ability to pass in multiple parameters(not just one), so it can be individually stopped, thus not needing to call stopAllCoroutines, or do the ever-so-nasty means of Deactivating a dummy-empty gameobject/empty that is housing a script-component with just that coRoutine on it. Using the traditional StopCoroutine on a non-string-based-explicitly-called CoRoutine fails constantly, thus my need to use the string-based call to start specific coroutines.

So perhaps it would look like this

StartCoroutine(“NameOfCoRoutineHere”, ParameterToPassHere1, ParameterToPassHere2, ParameterToPassHere3);

and say, each of the parameters is a different type, say a float for one, a string for another, and a transform for another.

something maybe like this for the method extension:

public static void StartCoroutine( this Coroutine StringToPassIn, int IntToPassIn, GameObject GameObjectToPassIn ){
Debug.Log(“test method extension”);
}

I cant seem to get this type of Extension working, as I usually do with a static class, I’m guessing it might have something to do with needing to inherit from monobehaviour to extend the startCoroutine method in such a way, not sure. Hoping a Unity Guru might be able to offer insight, thanks in advance for anyone taking the time to look this over and offer thoughts/help.

You just can’t extend the function! The easiest way is like Eric said using a Data-Object as parameter.

Another way would be to use your own coroutine handler. You can’t use the built-in “YieldInstructions” like WaitForSeconds or WaitForEndOfFrame but you can implement your own stuff for that. Even a WaitForFixedUpdate would be possible.

To be able to execute coroutines by string you would have to use reflection.

In most cases where you need something that is not supported by the language/engine, there are better design-patterns out there to achieve something similar.

Terminating coroutines from outside should not be necessary. It’s better to exit the coroutine regularly.

All internal datatypes used by Unity can’t be changed or even accessed. I’m quite sure that the coroutine management is done in C++ (since StartCoroutine wraps to an external function).