0
0
Unityframework~20 mins

WaitForSeconds and WaitForEndOfFrame in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Unity Coroutine Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of WaitForSeconds in Coroutine

What will be the output of this Unity C# coroutine code snippet?

Unity
IEnumerator ExampleCoroutine() {
    Debug.Log("Start");
    yield return new WaitForSeconds(1f);
    Debug.Log("After 1 second");
}
AStart immediately, then after 1 second print 'After 1 second'
BPrint both messages immediately without delay
CPrint only 'Start' and never print 'After 1 second'
DPrint 'After 1 second' first, then 'Start'
Attempts:
2 left
💡 Hint

Think about how WaitForSeconds pauses the coroutine.

Predict Output
intermediate
2:00remaining
When does WaitForEndOfFrame execute?

Consider this coroutine snippet. When will the message 'End of frame reached' be printed?

Unity
IEnumerator FrameCoroutine() {
    Debug.Log("Before waiting");
    yield return new WaitForEndOfFrame();
    Debug.Log("End of frame reached");
}
AAfter 1 second delay
BImmediately without waiting
CBefore rendering starts for the frame
DAfter all rendering for the current frame is done
Attempts:
2 left
💡 Hint

Think about the frame lifecycle in Unity and when WaitForEndOfFrame resumes.

🔧 Debug
advanced
2:00remaining
Why does this coroutine never print the second message?

Look at this coroutine code. Why does it never print 'Second message'?

Unity
IEnumerator TestCoroutine() {
    Debug.Log("First message");
    yield return new WaitForSeconds(-1f);
    Debug.Log("Second message");
}
AIt causes a compile error and never runs
BWaitForSeconds with negative time causes the coroutine to stop and never resume
CNegative time is treated as zero, so both messages print immediately
DThe coroutine throws an exception and stops
Attempts:
2 left
💡 Hint

Check how WaitForSeconds handles negative values.

🧠 Conceptual
advanced
2:00remaining
Difference between WaitForSeconds and WaitForEndOfFrame

Which statement correctly describes the difference between WaitForSeconds and WaitForEndOfFrame in Unity coroutines?

A<code>WaitForSeconds</code> pauses for a set time; <code>WaitForEndOfFrame</code> waits until the current frame finishes rendering
BBoth wait for a fixed time but differ in precision
C<code>WaitForSeconds</code> waits until the frame ends; <code>WaitForEndOfFrame</code> pauses for a set time
DBoth wait until the next frame starts
Attempts:
2 left
💡 Hint

Think about timing: fixed seconds vs frame lifecycle.

Predict Output
expert
2:00remaining
Number of times a message prints in this coroutine

Given this coroutine, how many times will 'Frame ended' print after starting it once?

Unity
IEnumerator LoopCoroutine() {
    while (true) {
        yield return new WaitForEndOfFrame();
        Debug.Log("Frame ended");
    }
}
AIt prints only once and then stops
BIt prints once per frame indefinitely until stopped
CIt never prints because of an infinite loop error
DIt prints twice per frame
Attempts:
2 left
💡 Hint

Consider what an infinite loop with WaitForEndOfFrame means in a coroutine.