I need to return an array from a coroutine, however it is illegal to use “ref” or “out” in a coroutine method. Does anyone know how to do this, short of making my own holder class to store the array reference in?
Store the array in a reference on the class that starts off the coroutine for example.
Ahhh. That would be simple wouldn’t it. The only problem is that the coroutine is a static method, which it doesn’t HAVE to be I guess. Instead I just made a class with a generic object
public class RefHolder {
public object holder;
}
and passed this to the coroutine. Then I just have to check to see when object holder is !=null and cast it back to my desired type.
I believe you can do this too:
yield return myArray;
The easiest way normally is to have a dictionary<> that stores the return basing on a unique key (that you passed into the coroutine for example). That way you can easily fetch it after the yield for the coroutine ended
Oooh, clever! Thanks dreamora.