Can coroutines be static?

Hi,

I asked chatGPT a question - can IEnumerators be static? To which I got the answer that no, "due to Unity specifics".

Maybe I didn’t google well, or maybe there wasn’t a specific question like that.
I wanted to know - is this true?

I can recommend my Coroutine Crash Course which I’ve written a while a go. It may help to better understand what coroutines are and how they work.

So by “coroutine” you could mean several different things. The original method that contains a yield keyword and returns an IEnumerator object actually can be a static method. The compiler doesn’t really care. However this original method is just the “generator” method and all it does is constructing an instance of the compiler generated class which is returned by your method. In order to run that as a coroutine you have to pass this object to Unity’s coroutine scheduler by passing it to the StartCoroutine method. This method is an instance method of the MonoBehaviour class. So in order to “run” a coroutine, you need an actual instance of a MonoBehaviour class as this will house the coroutine scheduler.

Since you haven’t mentioned a particular problem or usecase, this is where I’ll stop ^^.

No Coroutines can’t be static since they need a MonoBehaviour instance to run.