CoroutineInterruptToken

Class in Effects

Inherits from System.Object

Summary

An object that can be used to signal to a coroutine that it should terminate early.

public class CoroutineInterruptToken

Remarks

While coroutines can be stopped by calling MonoBehaviour.StopCoroutine or MonoBehaviour.StopAllCoroutines, this has the side effect of also stopping any coroutine that was waiting for the now-stopped coroutine to finish.

Instances of this class may be passed as a parameter to a coroutine that they can periodically poll to see if they should terminate earlier than planned.

To use this class, create an instance of it, and pass it as a parameter to your coroutine. In the coroutine, call Start() to mark that the coroutine is running. During the coroutine's execution, periodically check the WasInterrupted property to determine if the coroutine should exit. If it is true, the coroutine should exit (via the yield break statement.) At the normal exit of your coroutine, call the Complete() method to mark that the coroutine is no longer running. To make a coroutine stop, call the Interrupt() method.

You can also use the CanInterrupt property to determine if the token is in a state in which it can stop (that is, a coroutine that's using it is currently running.)

Methods

Properties

Last updated

Yarn Spinner® and Secret Lab® are trade marks of Secret Lab Pty. Ltd., and are used by Yarn Spinner Pty. Ltd. under license.