# C#: Callbacks

Source: https://tweens.gd/csharp/api/callbacks/

Callbacks are definition members that run synchronously at fixed points of each playback. [Await Completion](https://tweens.gd/csharp/playback/#react-to-the-end) shows one in use.

## Members

Each callback receives the playback’s `TweenInstance<TTarget, TValue>` handle; `OnUpdate` also receives the value it wrote. All default to `null`.

| Member | Runs |
| --- | --- |
| [`OnAdd`](https://tweens.gd/csharp/api/callbacks/#onadd) | At activation, after the start value is captured |
| [`OnStart`](https://tweens.gd/csharp/api/callbacks/#onstart) | Once, when the delay ends and playback begins |
| [`OnUpdate`](https://tweens.gd/csharp/api/callbacks/#onupdate) | After each write |
| [`OnEnd`](https://tweens.gd/csharp/api/callbacks/#onend) | On natural completion |
| [`OnCancel`](https://tweens.gd/csharp/api/callbacks/#oncancel) | When playback stops early: cancelled, target freed, owner exited, or runner disposed |
| [`OnFinally`](https://tweens.gd/csharp/api/callbacks/#onfinally) | Last, in every case, including faults |

## Suppressing callbacks

When ending callbacks touch the target, skip them once it’s gone:

| Member | Type | Default | Meaning |
| --- | --- | --- | --- |
| [`SuppressCallbacksWhenTargetInvalid`](https://tweens.gd/csharp/api/callbacks/#suppresscallbackswhentargetinvalid) | `bool` | `false` | Skip `OnEnd`, `OnCancel`, and `OnFinally` when the target or owner is gone, or playback ended with `TargetFreed` or `OwnerExited` |

## Callback order

1.  `OnAdd`, at activation after capture.
2.  `OnUpdate` with `From`, only when the [fill mode](https://tweens.gd/csharp/api/timing/#fill-and-restoration) applies it during the delay.
3.  `OnStart`, once, when the delay ends and playback begins.
4.  `OnUpdate` at each sampled timeline boundary and eligible update, plus once more when completion restores the initial value.
5.  `OnEnd` on natural completion, or `OnCancel` when playback stops early.
6.  `OnFinally`, in every case.

## Rules

-   The handle’s terminal state is visible before the terminal callbacks run, and each runs at most once.
-   A tween cancelled before activation, or whose preparation failed, runs no callbacks.
-   A long frame doesn’t replay the callbacks of the cycles it skipped.
-   An exception in a callback [faults](https://tweens.gd/csharp/api/handles/#errors) the tween; `OnFinally` still runs.
-   Tweens started in a callback or after an await are independent: they begin on the next eligible update, with no inherited frame time. A [Chain](https://tweens.gd/csharp/api/chains/) links timing instead.
