0

I'm trying to learn how to use Coroutines with Unity and I'm having trouble and keep getting a nullreferenceexception.

I've read a number of pages on this same issue from stack exchange and unity but I can't seem to tie the answers to my own code.

public void takeTopTask(Queue queue){
    if (availability == false) {
        Debug.LogError (name+" is not available to take a task");
    } else {
        task takenTask = (task)queue.Dequeue ();
        string taskName = takenTask.getName ();
        Debug.Log (taskName + " was taken by " + name);
        StartCoroutine(doTask(takenTask));
    }
}

IEnumerator doTask(task task){
    //do the task or something
    yield return new WaitForSeconds (task.getLength ());
}

Any help would be HUGELY appreciated!

  • You need to go though the duplicate and do the basic debugging first. Figure out what is null, then find where a value was assigned to it and figure out why it is null. – Scott Chamberlain Jul 12 '17 at 00:12
  • If you double-click on the error, it will show you which line of code is causing that problem. – Programmer Jul 12 '17 at 00:13

0 Answers0