Can you use coroutines like this?

My coroutine looks like this:

{
Texture2D tex1=generateTexture(parameters...);
yield return null;
Texture2D tex2=generateTexture(parameters...);
yield return null;
...
}

The problem is, generateTexure is a very heavy task that can take minutes, and I need it to yield during the steps it takes.

How do I add yields inside that generateTexture method, as if I unrolled the method into the calling coroutine and used yield there?

You’d have to do exactly that: add yields inside that generateTexture method, in other words, turn that method itself into a coroutine, then you could yield for it in this coroutine like this:

yield return generateTexture(parameters...);

Of course you’d have to pass in a ref variable or something to get results out of it.

1 Like