How to refactor a long coroutine method in several shorter methods ?

I have the following code :

void Start()
{
    StartCoroutine(LoadObjects());
}

IEnumerator LoadObjects()
{	
	//load objectsA
	for(int i = 0 ; i < 100 ; i++)
	{
		//load object A
		//...
		yield return new WaitForEndOfFrame();
	}

	//load objectsB
	for(int i = 0 ; i < 100 ; i++)
	{
		//load object B
		//...
		yield return new WaitForEndOfFrame();
	}

	//load objectsC
	//...
}

I would like to refactor and extract object loading code in separate methods :

IEnumerator LoadObjects()
{	
	//load objectsA
	LoadObjectA();

	//load objectsB
	LoadObjectB();
}

IEnumerator LoadObjectA()
{
	for(int i = 0 ; i < 100 ; i++)
	{
		//load object A
		//...
		yield return new WaitForEndOfFrame();
	}
}

IEnumerator LoadObjectB()
{
	for(int i = 0 ; i < 100 ; i++)
	{
	    //load object B
		//...
		yield return new WaitForEndOfFrame();
	}
}

I have tried to put “yield return” in front of “LoadObjectA();” and “LoadObjectB();” calls. While it compiles, it does not works (loading object methods are not called).

How can I have exact same behavior as before, but with code in LoadObjects splitted?

What you have works, you just made a simple mistake.

ALL coroutines need to be called using StartCoroutine, even if you’re calling it from inside another coroutine. Use yield return StartCoroutine(subpartGoesHere());

Then, yes, the way the system is setup, not using StartCoroutine gives no errors, but doesn’t run it either (I’m pretty impressed the Unity team found a way to do this at all.)