- Home /
Question by
Haapavuo · Jan 05, 2019 at 12:17 PM ·
coroutineienumeratorcallstartcoroutinewarning
Is there a way to show a warning when a Coroutine is called directly?
In Unity, it is possible to call an IEnumerator method (or Coroutine) using a normal function call. However, you should always start Coroutines by calling the StartCoroutine method or using yield return from another Coroutine.
public void Start()
{
// Correct way to call coroutines
StartCoroutine(MyCoroutine());
// Wrong way to call coroutines
MyCoroutine();
}
public IEnumerator MyCoroutine()
{
// Correct way to call coroutines
yield return MyAnotherCoroutine();
}
public IEnumerator MyAnotherCoroutine()
{
// TODO
}
Is there a way to implement an extension that will log a warning when any Coroutine method is called without calling through StartCoroutine() or from another Coroutine? Thanks.
I am thinking of a [Coroutine] Attribute that could be placed manually for all the Coroutine methods that we have implemented. I just don't know how I could check if the method was called properly or not.
Comment