There are multiple ways to delay a task in Unity. You can either make your own timer function or use the inbuilt feature like async await. If your intention is not to display the timer then there is no need to make a timer function in Unity. You will delay a lot of tasks, during your journey of making your own game and while learning Unity. So, this is an important C# feature to master.
In this tutorial, we will see how to use async await to delay a task in Unity. If you are using Unity 2018 or below then async will not work, you will have to use a coroutine for delay.
We will start with a simple code, that will debug log a message after a delay of 2 seconds. To use the async delay, follow the steps below.
- Add using
System.Threading.Tasksnamespace to your script. - Set the function type, where you want to execute the delay as async. In the below code, it’s the start function.
- Use
await Task.Delay(delay time in milli seconds). - Call the code to be delayed after await statement.
Here is the complete code with all the above steps executed.
using UnityEngine;
using System.Threading.Tasks;
public class Example_timer : MonoBehaviour
{
async void Start()
{
await Task.Delay(2000); //time in millisecond
Debug.Log("Called after 2 seconds of game start");
}
}
Using async await to delay foreach loop
The unique feature of async is, it can be used to delay each loop of a for or foreach loop. The below code delays every loop by 1 second. As we saw in the play audio clip tutorial, we can use this to play audio clips in a sequence.
using UnityEngine;
using System.Threading.Tasks;
public class Example_timer : MonoBehaviour
{
async void Start()
{
for(int i=0;i<10;i++)
{
await Task.Delay(1000); //time input is in milliseconds
Debug.Log(i);
}
}
}
Coroutine vs Async
In Unity, both async/await and coroutines can manage delays, but they achieve it differently. async/await utilizes C#’s built-in asynchronous programming features, pausing execution until the awaited operation completes without blocking the main thread. Coroutines, on the other hand, are Unity’s own mechanism for spreading execution over multiple frames using yield return. Choosing the right approach depends on the specific scenario.
- Async/Await:
- Leverages C# language features.
- Truly asynchronous, doesn’t rely on Unity’s frame updates.
- Better for integrating with external asynchronous operations (e.g., network requests).
- Coroutines:
- Unity-specific.
- Tied to the game’s frame loop.
- Simpler for tasks tightly coupled with game logic (e.g., animations, timed sequences).
Hope the concept of Async await is clear. If you have any other questions, feel free to leave a comment below.
For the next tutorial, let’s create an Enemy AI that follows the player using Navmesh.

That HANGS everything and does not recover.
Please share your code.