UNT0012 Unused Coroutine Return Value

January 31, 2020 ยท View on GitHub

Wrap calls to coroutines in StartCoroutine(). Failure to do so will result in the coroutine not being executed.

Examples of patterns that are flagged by this analyzer

using System.Collections;
using UnityEngine;

public class UnusedCoroutineScript : MonoBehaviour
{
    void Start()
    {
        UnusedCoroutine(2.0f);
    }

    private IEnumerator UnusedCoroutine(float waitTime)
    {
        for (int i = 0; i < 10; i++)
        {
            yield return new WaitForSeconds(waitTime);
        }
    }
}

Solution

Wrap calls to coroutines in StartCoroutine():

using System.Collections;
using UnityEngine;

public class UnusedCoroutineScript : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(UnusedCoroutine(2.0f));
    }

    private IEnumerator UnusedCoroutine(float waitTime)
    {
        for (int i = 0; i < 10; i++)
        {
            yield return new WaitForSeconds(waitTime);
        }
    }
}

A code fix is offered for this diagnostic to automatically apply this change.