> For the complete documentation index, see [llms.txt](https://pahutyakv.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pahutyakv.gitbook.io/docs/delayed/delayed-chains.md).

# Delayed Chains

The `Delayed.Chains` module allow you to sequence multiple delayed actions into an ordered workflow. Each step is executed only after the previous step completes. Chains can loop, be paused, resumed, or canceled, providing powerful control over complex sequences.

***

### <mark style="color:$success;">Methods</mark>

* `Pause() / Resume()` – temporarily suspend or resume execution.
* `Cancel()` – immediately stops the chain and invokes the `OnCancel` event.
* `Loop(int times = -1)` - sets how many times the chain should repeat after completion. Use `-1` for infinite looping.

***

### <mark style="color:$success;">Built-in Steps</mark>

Provides a fluent API for adding the most common step types to the chain.

* `Do(Action callback)` – executes a callback immediately.
* `Seconds(float seconds, bool ignoreTimeScale = false)` – waits for the specified number of seconds before continuing.
* `Frames(int frames)` – waits for the specified number of frames before continuing.
* `WaitFor(params Func[] conditions)` – waits until all specified conditions return true before continuing.

{% code overflow="wrap" %}

```csharp
DelayedChain chain = Delayed.Chains.Chain()
    .Do(() => Debug.Log("Started"))
    .Seconds(2)
    .Frames(60)
    .WaitFor(() => player.IsReady)
    .Do(() => Debug.Log("Finished"));
```

{% endcode %}

***

### <mark style="color:$success;">Custom Steps</mark>

For custom scenarios, `AddStep()` allows you to add any DelayedAction to the chain by providing an action factory. This makes it possible to combine built-in step types with any custom delayed action.

{% code overflow="wrap" %}

```csharp
DelayedChain chain = Delayed.Chains.Chain()
    .AddStep(() => Delayed.Frames.After(300, () => Debug.Log("300 frames!")))
    .AddStep(() => Delayed.Time.After(3, () => Debug.Log("After 3 seconds!")));
```

{% endcode %}

***

### <mark style="color:$success;">Events</mark>

<details>

<summary><strong>OnComplete(Action callback / Action callback)</strong></summary>

Called when the entire chain finishes execution.

```csharp
chain.OnComplete(() => Debug.Log("Chain completed!"));
```

</details>

<details>

<summary><strong>OnCancel(Action callback / Action callback)</strong></summary>

Called if the chain is canceled before completion.

```csharp
chain.OnCancel(() => Debug.Log("Chain canceled!"));
```

</details>

***

### <mark style="color:$primary;">Notes</mark>

* Chains internally queue the delayed actions and execute them one by one.
* Each step can be any type of delayed action (Immediate, Time-based, Frame-based, Condition-based).
* Supports looping, which restarts the sequence automatically after completion.
* Provides sequential control of actions, making it ideal for complex gameplay sequences, cutscenes, or timed tutorials.
