hi im unity starter and… (I’m sorry) i’m not very good at english.
well… i have some unity study book and this book introduce the following ways
IEnumerator Test()
{
Instantiate(~~); <--- take 20 sec
yield return null;
}
is it work?
what is different next way?
void Test()
{
Instantiate(~~); <--- take 20 sec
}
thank you
The first uses an IEnumerator
, which is the standard pattern in Unity when calling coroutines. Coroutines are a pretty cool concept themselves. Effectively, you’re creating a method that can pause and resume execution at any point you let it – yielding program execution.
If your measure of performance is the Update()
method freezing or not, then yes the coroutine will not freeze that method. This is because coroutines will execute after the update method has finished.
Understand though, that coroutines are not executing at the same time (in parallel) as other code, they are executing in sequence (serially). The total time to run the Instantiate() method still will not change either way.