Process

Coroutines or Async/Await in Unity: Which and When

Both run code over several frames, and both can bite you. Here is when we reach for coroutines, when async/await is the better tool, and how to avoid the lifetime bug that catches most teams.

Vectra Play 5 min read
A programmer reading C# code on a wide monitor with a phone test device propped beside the keyboard

For Unity coroutines vs async await, a simple rule works: use coroutines for gameplay sequences tied to one GameObject, and async/await for work that returns a value, such as loading, saving or network calls. Coroutines stop when their object is deactivated or destroyed. Async methods keep running unless you cancel them, which is the main trap.

The quick comparison

CoroutinesAsync/await
Lives onA MonoBehaviourAny C# method
Stops when object is disabledYes, if the GameObject is deactivatedNo, unless cancelled
Returns a valueNot directlyYes
Error handlingLogs and stopstry/catch works normally
Waiting on framesyield return nullawait Awaitable.NextFrameAsync() in Unity 6
Best forTimed gameplay sequencesLoading, saving, web requests

Both run on the main thread by default. Neither makes code faster on its own; they only spread work across time.

Where coroutines still win

Coroutines are simple and their lifetime is automatic. A sequence that belongs to one object dies with that object, which is usually what you want.

Good fits:

One detail worth knowing: deactivating the GameObject stops its coroutines, but setting the component's enabled to false does not. If an effect keeps running on a disabled component, that is why.

Cache your wait objects. new WaitForSeconds(0.5f) allocates each time, so store it in a field if the coroutine runs often.

Where async/await is the better tool

Async/await shines when work produces a result or chains several steps. The code reads top to bottom, and try/catch works as you expect.

Good fits:

Our save system guide uses this pattern for loading and writing saves without blocking the frame.

The lifetime trap

An async method keeps running after its object is destroyed. If a player leaves a scene while an await is pending, the method resumes later and touches an object that no longer exists.

Since Unity 2022.2, every MonoBehaviour has destroyCancellationToken. Pass it into your awaits and the method stops cleanly when the object goes away.

async void Start()
{
    try
    {
        await Awaitable.WaitForSecondsAsync(2f, destroyCancellationToken);
        ShowTip();
    }
    catch (OperationCanceledException) { }
}

The Awaitable class arrived in Unity 2023.1, which became Unity 6. On older versions, pass the token into your own methods and check it after each await.

Every await inside a MonoBehaviour should take a cancellation token. Make it a habit and the most common async bug disappears.

Awaitable, Task and allocations

On Unity 6, prefer Awaitable for frame-based waits. It has NextFrameAsync, WaitForSecondsAsync, EndOfFrameAsync, and BackgroundThreadAsync with MainThreadAsync for moving heavy work off the main thread and back.

Awaitable objects are pooled to cut garbage, so await each one only once. Standard Task works in Unity too, but it allocates more, which matters in hot paths on mobile.

Many teams use the open-source UniTask library for low-allocation async on older Unity versions. It is a solid option, though on Unity 6 you may not need it.

Errors and debugging

Coroutines log an exception and stop, which is easy to spot. Async methods behave differently depending on how they are called.

  1. async void methods log exceptions to the Console in Unity, so you will see them.
  2. async Task methods nobody awaits can fail quietly, because the exception sits inside the task.
  3. Background thread code cannot touch most Unity APIs, so switch back with MainThreadAsync before using them.

Keep async void for Unity event methods like Start, and return Task or Awaitable everywhere else so callers can await and catch errors.

A simple rule set for a project

Teams argue less when the rules are written down, and a mixed codebase stays readable when everyone follows the same split. New people can tell at a glance whether a method is a gameplay sequence or a piece of loading work.

This is the set we use:

What we would do

We would keep coroutines for small visual and gameplay sequences and move all loading, saving and network code to async with cancellation tokens. On Unity 6 we would use Awaitable and skip extra libraries unless profiling showed a need.

Then we would add the rule set to the project readme, so anyone joining later follows the same pattern.

The short version

If your project has async code that keeps throwing after scene changes, we are happy to take a look.

Related reading: Scriptable Objects for game config, Unity packages worth importing, Unity object pooling for mobile stutter

#Unity#Development#Tools#Mobile
Your turn

Got a game idea? We build it.

You bring the concept. We design, build, test and launch it, and you own 100% of the finished game.

Share Your Game Idea  →