Problen with yield C#. Odd behaviour?

public IEnumerator Load (int id)
{
        Debug.Log("This is the first");
        yield return 0;
        Debug.Log("This is the second");
}

//Code that is executed first

Debug.Log("Starting");
Loader loader = new Loader();
loader.Load(1);
Debug.Log("Ending");

Well, I don’t know why messages “This is the first” and "This is the second are not printing.

I expect from this example following output:
“Starting”, “This is First One”, “Ending”, “This is Second One”

but I just get “Starting”,“Ending”.

Could anybody please bring some light?

Thanks in advance,
HexDump.

Hi!,

It seems that it works as intended using StarCoroutine. I thought I should only use StartCoroutine when in Update or FIxedUpdate, or this what I remember docs stated :/.

Thanks in advance,
HexDump.

Startcoroutine can always be used and is actually required, otherwise yields are ignored or even lead to compiler errors

what you can not do is yield it in some functions (like Start)

The confusion may come from the fact that StartCoroutine() is implicit (i.e. you don’t need to use it at all) in UnityScript; in C#, as dreamora said, it is required.

Thanks for the answers,

HexDump.