0
0
Unityframework~10 mins

WaitForSeconds and WaitForEndOfFrame in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - WaitForSeconds and WaitForEndOfFrame
Start Coroutine
Yield WaitForSeconds
Wait real time seconds
Resume after delay
Yield WaitForEndOfFrame
Wait until frame ends
Resume next frame
Coroutine ends
The coroutine pauses at WaitForSeconds for a set time, then resumes and pauses again at WaitForEndOfFrame until the current frame finishes, then continues.
Execution Sample
Unity
IEnumerator Example() {
  Debug.Log("Start");
  yield return new WaitForSeconds(2);
  Debug.Log("After 2 seconds");
  yield return new WaitForEndOfFrame();
  Debug.Log("End of frame");
}
This coroutine logs a message, waits 2 seconds, logs again, waits until the frame ends, then logs a final message.
Execution Table
StepActionYieldWait Time / ConditionOutput
1Start coroutineNoneNoneLogs: Start
2Yield WaitForSecondsWaitForSeconds2 seconds real timePauses coroutine
3Resume after 2 secondsNoneTime passedLogs: After 2 seconds
4Yield WaitForEndOfFrameWaitForEndOfFrameUntil current frame endsPauses coroutine
5Resume after frame endsNoneFrame finishedLogs: End of frame
6Coroutine endsNoneNoneCoroutine stops
💡 Coroutine stops after completing all yield instructions
Variable Tracker
VariableStartAfter Step 2After Step 4Final
Coroutine StateNot startedWaiting 2 secondsWaiting end of frameCompleted
Key Moments - 3 Insights
Why does the coroutine pause at WaitForSeconds?
Because WaitForSeconds tells Unity to pause the coroutine for the specified real time seconds before continuing, as shown in step 2 of the execution_table.
What does WaitForEndOfFrame wait for exactly?
It waits until the current frame finishes rendering before resuming the coroutine, as shown in step 4 and 5 of the execution_table.
Does WaitForSeconds wait for game frames or real time?
WaitForSeconds waits for real time seconds, not frames, so it can pause across multiple frames, as seen between steps 2 and 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the coroutine state after step 2?
AWaiting end of frame
BWaiting 2 seconds
CCompleted
DNot started
💡 Hint
Check variable_tracker row 'Coroutine State' after step 2
At which step does the coroutine resume after waiting for the frame to end?
AStep 5
BStep 4
CStep 3
DStep 6
💡 Hint
See execution_table step 5 where it logs 'End of frame'
If WaitForSeconds was changed to 0, what would happen at step 2?
ACoroutine pauses for 2 seconds
BCoroutine pauses until frame ends
CCoroutine continues immediately without pause
DCoroutine stops
💡 Hint
WaitForSeconds with 0 means no delay, so coroutine continues immediately after step 2
Concept Snapshot
WaitForSeconds pauses coroutine for given seconds (real time).
WaitForEndOfFrame pauses coroutine until current frame finishes rendering.
Use yield return with these to delay actions.
WaitForSeconds can span multiple frames.
WaitForEndOfFrame resumes next frame after rendering.
Both help control timing in Unity coroutines.
Full Transcript
This visual execution shows how Unity coroutines pause and resume using WaitForSeconds and WaitForEndOfFrame. The coroutine starts and logs a message. Then it yields WaitForSeconds, pausing for 2 seconds real time before resuming and logging again. Next, it yields WaitForEndOfFrame, pausing until the current frame finishes rendering. After the frame ends, it resumes and logs a final message before ending. Variables track the coroutine state changing from not started, to waiting 2 seconds, to waiting end of frame, then completed. Key moments clarify that WaitForSeconds waits real time seconds, not frames, and WaitForEndOfFrame waits until the frame finishes. The quiz tests understanding of coroutine states and timing. This helps beginners see exactly when and why coroutines pause and resume in Unity.