# WaitUntil

> Suspends the coroutine execution until the supplied delegate evaluates to true.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine](/engine/6000.6/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule
* **Inherits from:** [CustomYieldInstruction](/engine/6000.6/script-reference/unityengine/customyieldinstruction.md)
* **Implements:** [IEnumerator](https://learn.microsoft.com/dotnet/api/system.collections.ienumerator)

```csharp
public sealed class WaitUntil : CustomYieldInstruction, IEnumerator
```

## Remarks

`WaitUntil` can only be used with a `yield` statement in coroutines.

The supplied delegate is executed each frame after [MonoBehaviour.Update()](/engine/6000.6/script-reference/unityengine/monobehaviour/update.md) and before [MonoBehaviour.LateUpdate()](/engine/6000.6/script-reference/unityengine/monobehaviour/lateupdate.md). When the delegate evaluates to `true`, the coroutine resumes.

Additional Resources: [AsyncOperation](/engine/6000.6/script-reference/unityengine/asyncoperation.md), [WaitForEndOfFrame](/engine/6000.6/script-reference/unityengine/waitforendofframe.md), [WaitForFixedUpdate](/engine/6000.6/script-reference/unityengine/waitforfixedupdate.md), [WaitForSeconds](/engine/6000.6/script-reference/unityengine/waitforseconds.md), [WaitForSecondsRealtime](/engine/6000.6/script-reference/unityengine/waitforsecondsrealtime.md), [WaitWhile](/engine/6000.6/script-reference/unityengine/waitwhile.md).

## Examples

```csharp
using UnityEngine;
using System.Collections;

public class WaitUntilExample : MonoBehaviour
{
    public int frame;

    void Start()
    {
        StartCoroutine(Example());
    }

    IEnumerator Example()
    {
        Debug.Log("Waiting for princess to be rescued...");
        yield return new WaitUntil(() => frame >= 10);
        Debug.Log("Princess was rescued!");
    }

    void Update()
    {
        if (frame <= 10)
        {
            Debug.Log("Frame: " + frame);
            frame++;
        }
    }
}
```

## Constructors

| Constructor                                                                                                                                                                                                              | Description                                                            |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------- |
| [WaitUntil(System.Func\{System.Boolean})](/engine/6000.6/script-reference/unityengine/waituntil/ctor.md#waituntil\(funcbool\))                                                                                           | Initializes a yield instruction with a given delegate to be evaluated. |
| [WaitUntil(System.Func\{System.Boolean},System.TimeSpan,System.Action,UnityEngine.WaitTimeoutMode)](/engine/6000.6/script-reference/unityengine/waituntil/ctor.md#waituntil\(funcbool-timespan-action-waittimeoutmode\)) | Initializes a yield instruction with a given delegate to be evaluated. |

## Inheritance

**Inherited Members:**

* [CustomYieldInstruction.keepWaiting](/engine/6000.6/script-reference/unityengine/customyieldinstruction/keepwaiting.md)
