- Home /
NullReferenceException: (null)
This is the code in my GameController script:
public IEnumerator GameStart()
{
StartCoroutine(StageOneEnemyRoutine.StartAttack());
return null;
}
Here is the code in my StageOneEnemyRoutine script:
public static IEnumerator StartAttack()
{
float currentTime = Time.time;
while(Time.time <= currentTime + 120.0f)
{
if (portalCount < 2)
{
SpawnPortal();
return null;
}
if (GameController.GameIsOver())
break;
return null;
}
return null;
}
In the IDE there are no errors and everything compiles correctly. However, when I start the game and reach the point where the Coroutine is called I get the NullReferenceException error on the GameController script.
I have no idea why. Any help?
Well maybe you should show us the GameIsOver method script eh genius?
You could ask that in a less asshole-ish way, but since you did ask, here ya go...
public static bool GameIsOver()
{
return gameOver;
}
Answer by ShadyProductions · Aug 08, 2017 at 06:57 AM
Okay so you should replace all the 'return null' with yield break; That should fix it, it will exit out of the coroutine.
or basically put a yield return null;
An IEnumerator always needs to yield
Your answer
Follow this Question
Related Questions
AppDomain.UnhandledException on Android 0 Answers
Unity seems to be silently suppressing exception dialogs, and showing no messages. Why is that? 1 Answer
Random Unrelated Exceptions thrown in WebGL Build (unity 2018) 1 Answer
ArgumentOutOfRangeException: Argument is out of range? What wrong? 1 Answer
I'm having issue with following stack trace. I can't understand what's causing that. 0 Answers