For AI agents: the complete documentation index is available at /AchEngine/en/llms.txt, the full documentation bundle is available at /AchEngine/en/llms-full.txt, and this page is available as Markdown at /AchEngine/en/usage/timer.md.

AchTimer

AchTimer is an async/await timer utility for simple delays and progress tracking.

Simple waits

await AchTimer.Wait(3f);
await AchTimer.WaitRealtime(3f);

Wait uses game time; WaitRealtime uses unscaled time and is unaffected by slow motion or pause.

Track progress with AchTimerHandle

var timer = AchTimer.Start(5f);
await timer;
PropertyDescription
DurationTotal duration in seconds
ElapsedElapsed seconds
RemainingRemaining seconds, never below zero
Progress0 to 1 completion ratio
IsDoneCompleted or canceled
IsCancelledCanceled state
TaskTask representing completion

await timer and await timer.Task are equivalent. Cancellation raises TaskCanceledException.

var timer = AchTimer.Start(10f);
if (playerDied)
    timer.Cancel();

Use useUnscaledTime: true for a real-time timer and pass a CancellationToken when an external owner should cancel it.

var cts = new CancellationTokenSource();
await AchTimer.Wait(10f, cts.Token);
var timer = AchTimer.Start(10f, cancellationToken: cts.Token);

UIAchTimer

Bind a handle to optional Text and Slider fields to display remaining/elapsed time and progress.

var timer = AchTimer.Start(5f);
GetComponent<UIAchTimer>().Bind(timer);
await timer;

The component unbinds automatically when the timer completes; call Unbind() manually when needed.

Complete example

var cts = new CancellationTokenSource();
var castTimer = AchTimer.Start(2f, cancellationToken: cts.Token);
castBar.Bind(castTimer);

try
{
    await castTimer;
    FireSkill();
}
catch (TaskCanceledException)
{
    ShowCancelMessage();
}