Bird
Raised Fist0
Unityframework~20 mins

Coroutine chaining in Unity - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What does yield return StartCoroutine() do in Unity coroutine chaining?
easy
A. It immediately stops all coroutines running in the script.
B. It waits for the called coroutine to finish before continuing.
C. It starts a coroutine but does not wait for it to finish.
D. It pauses the game until the coroutine completes.

Solution

  1. Step 1: Understand coroutine chaining

    Coroutine chaining means running one coroutine after another finishes.
  2. Step 2: Role of yield return StartCoroutine()

    This statement pauses the current coroutine until the called coroutine completes.
  3. Final Answer:

    It waits for the called coroutine to finish before continuing. -> Option B
  4. Quick Check:

    Yield return StartCoroutine waits for completion [OK]
Hint: Remember: yield return waits for coroutine to finish [OK]
Common Mistakes:
  • Thinking it stops all coroutines
  • Assuming it doesn't wait for completion
  • Confusing it with pausing the entire game
2. Which of the following is the correct syntax to chain two coroutines First() and Second() in Unity?
easy
A. yield return First; yield return Second;
B. StartCoroutine(First()); StartCoroutine(Second());
C. StartCoroutine(First()); yield return Second();
D. yield return StartCoroutine(First()); yield return StartCoroutine(Second());

Solution

  1. Step 1: Identify correct coroutine chaining syntax

    To chain coroutines, you must yield return StartCoroutine to wait for each to finish.
  2. Step 2: Analyze options

    yield return StartCoroutine(First()); yield return StartCoroutine(Second()); uses yield return StartCoroutine for both, correctly chaining them.
  3. Final Answer:

    yield return StartCoroutine(First()); yield return StartCoroutine(Second()); -> Option D
  4. Quick Check:

    Correct chaining uses yield return StartCoroutine [OK]
Hint: Use yield return StartCoroutine to chain coroutines [OK]
Common Mistakes:
  • Calling coroutines without yield return
  • Using yield return without StartCoroutine
  • Starting coroutines without waiting
3. What will be the output order when running this Unity coroutine code?
IEnumerator First() {
    Debug.Log("Start First");
    yield return new WaitForSeconds(1);
    Debug.Log("End First");
}

IEnumerator Second() {
    Debug.Log("Start Second");
    yield return new WaitForSeconds(1);
    Debug.Log("End Second");
}

IEnumerator Chain() {
    yield return StartCoroutine(First());
    yield return StartCoroutine(Second());
    Debug.Log("Chain Complete");
}
medium
A. ["Start First", "End First", "Start Second", "End Second", "Chain Complete"]
B. ["Start First", "Start Second", "End First", "End Second", "Chain Complete"]
C. ["Start First", "End First", "Chain Complete", "Start Second", "End Second"]
D. ["Start First", "Start Second", "Chain Complete", "End First", "End Second"]

Solution

  1. Step 1: Understand coroutine chaining order

    Chain waits for First to finish before starting Second, then logs completion.
  2. Step 2: Trace output sequence

    First logs start, waits 1s, logs end; then Second logs start, waits 1s, logs end; finally Chain logs complete.
  3. Final Answer:

    ["Start First", "End First", "Start Second", "End Second", "Chain Complete"] -> Option A
  4. Quick Check:

    Chained coroutines run sequentially [OK]
Hint: Chained coroutines run fully one after another [OK]
Common Mistakes:
  • Assuming coroutines run in parallel
  • Expecting logs to mix order
  • Missing that Chain logs last
4. Identify the error in this coroutine chaining code snippet:
IEnumerator Chain() {
    StartCoroutine(First());
    yield return StartCoroutine(Second());
    Debug.Log("Done");
}
medium
A. Debug.Log("Done") is called before any coroutine.
B. Second coroutine is not started correctly.
C. First coroutine is started but not waited for before Second starts.
D. Chain coroutine should not use yield return.

Solution

  1. Step 1: Check how coroutines are started and waited

    First coroutine is started without yield return, so Chain does not wait for it.
  2. Step 2: Understand effect on chaining

    Second coroutine waits correctly, but First runs in parallel, breaking chaining order.
  3. Final Answer:

    First coroutine is started but not waited for before Second starts. -> Option C
  4. Quick Check:

    StartCoroutine without yield return doesn't wait [OK]
Hint: Always yield return StartCoroutine to wait [OK]
Common Mistakes:
  • Starting coroutine without yield return
  • Assuming StartCoroutine waits automatically
  • Misunderstanding coroutine execution order
5. You want to chain three coroutines LoadData(), ProcessData(), and DisplayData() so each starts only after the previous finishes. Which code snippet correctly implements this chaining?
hard
A. yield return StartCoroutine(LoadData()); yield return StartCoroutine(ProcessData()); yield return StartCoroutine(DisplayData());
B. StartCoroutine(LoadData()); StartCoroutine(ProcessData()); StartCoroutine(DisplayData());
C. yield return LoadData; yield return ProcessData; yield return DisplayData;
D. StartCoroutine(LoadData()); yield return ProcessData(); yield return DisplayData();

Solution

  1. Step 1: Understand chaining requirement

    Each coroutine must finish before the next starts, so we must wait for each.
  2. Step 2: Analyze correct chaining syntax

    Using yield return StartCoroutine ensures waiting for each coroutine to complete before continuing.
  3. Final Answer:

    yield return StartCoroutine(LoadData()); yield return StartCoroutine(ProcessData()); yield return StartCoroutine(DisplayData()); -> Option A
  4. Quick Check:

    Yield return StartCoroutine chains coroutines sequentially [OK]
Hint: Chain with yield return StartCoroutine for sequential execution [OK]
Common Mistakes:
  • Starting all coroutines without waiting
  • Yield returning coroutine call without StartCoroutine
  • Mixing yield return and StartCoroutine incorrectly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard