I am getting crash reports from players (using an automated error reporting system), although i cannot seem to reproduce this issue.
For some reason, a certain piece of code that starts a coroutine throws a null reference exception:
StartCoroutine(LoadLevelDelayed());
// This method is defined properly, returning an IEnumerator and yielding at certain points.
private IEnumerator LoadLevelDelayed()
{
// ...
}
This script is attached to a game object that is saved inside a scene (i’ve seen other posts where people tried to manually instantiate MonoBehaviour objects and that was the cause of failure).
Other information that may be related is that the call to StartCoroutine occurs inside an anonymous delegate, e.g:
public class Something : MonoBehaviour
{
public void SomeMethod()
{
CallAnotherMethod(
delegate(bool success)
{
StartCoroutine(LoadLevelDelayed());
});
}
private IEnumerator LoadLevelDelayed()
{
// ..
}
}
What else can lead to a NRE thrown when calling this method (StartCoroutine) ?