0
0
Unityframework~20 mins

Coroutine chaining in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Coroutine Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of chained coroutines with WaitForSeconds
What will be the output sequence and timing when running this Unity coroutine chaining code?
Unity
using System.Collections;
using UnityEngine;

public class TestChain : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(First());
    }

    IEnumerator First()
    {
        Debug.Log("Start First");
        yield return StartCoroutine(Second());
        Debug.Log("End First");
    }

    IEnumerator Second()
    {
        Debug.Log("Start Second");
        yield return new WaitForSeconds(1);
        Debug.Log("End Second");
    }
}
AStart First, Start Second, End First, End Second (after 1 second)
BStart First, End First, Start Second, End Second (after 1 second)
CStart First, Start Second, End Second (after 1 second), End First immediately after
DStart Second, Start First, End Second (after 1 second), End First
Attempts:
2 left
💡 Hint
Remember that yield return StartCoroutine waits for the inner coroutine to finish before continuing.
🧠 Conceptual
intermediate
1:30remaining
Understanding yield return null in coroutine chaining
In Unity coroutine chaining, what does yield return null do inside a coroutine?
AImmediately continues without waiting
BStops the coroutine permanently
CWaits for 1 second before continuing
DPauses the coroutine until the next frame before continuing
Attempts:
2 left
💡 Hint
Think about what happens when you want to wait just one frame.
🔧 Debug
advanced
2:00remaining
Identify the error in coroutine chaining code
What error will this Unity coroutine chaining code produce when run?
Unity
IEnumerator First()
{
    Debug.Log("First start");
    yield return Second();
    Debug.Log("First end");
}

IEnumerator Second()
{
    Debug.Log("Second start");
    yield return new WaitForSeconds(1);
    Debug.Log("Second end");
}
ASecond coroutine runs but First does not wait for it to finish
BNo error, runs correctly with expected output
CCompile-time error due to missing StartCoroutine call
DRuntime error: NullReferenceException
Attempts:
2 left
💡 Hint
Check how coroutines are started and chained properly.
📝 Syntax
advanced
2:00remaining
Correct syntax for chaining multiple coroutines
Which option correctly chains two coroutines so that Second runs after First finishes?
Unity
IEnumerator First() { Debug.Log("First"); yield return new WaitForSeconds(1); }
IEnumerator Second() { Debug.Log("Second"); yield return new WaitForSeconds(1); }
AStartCoroutine(First()); StartCoroutine(Second());
Byield return StartCoroutine(First()); yield return StartCoroutine(Second());
Cyield return First(); yield return Second();
Dyield return new WaitForSeconds(1); yield return new WaitForSeconds(1);
Attempts:
2 left
💡 Hint
Remember how to wait for one coroutine to finish before starting another.
🚀 Application
expert
3:00remaining
Chaining coroutines with conditional wait and result passing
Given these two coroutines, what will be the value of 'result' after running the Chain coroutine?
Unity
IEnumerator WaitAndReturn(int waitSeconds, System.Action<int> callback)
{
    yield return new WaitForSeconds(waitSeconds);
    callback(waitSeconds * 2);
}

IEnumerator Chain()
{
    int result = 0;
    yield return StartCoroutine(WaitAndReturn(2, x => result = x));
    Debug.Log($"Result is {result}");
}
AResult is 4
BResult is 2
CResult is 0
DNo output, coroutine never finishes
Attempts:
2 left
💡 Hint
Look at how the callback sets the result after waiting.