Hi
I have the following code which produced the error “NullReferenceException: Object reference not set to an instance of an object” at the line where I try to enqueue one of the linkedDialogues but I’m not sure why I am getting the error because if I log the object I seem to be able to access it. The Dialogues extend ScriptableObject. I’m not sure if this is the problem. Any ideas anyone?
float currentPosX = 20.0f;
Queue<Dialogue> queue = new Queue<Dialogue>();
queue.Enqueue(workingSequence.RootDialogue);
while(queue.Count > 0)
{
Dialogue currentDialogue = queue.Dequeue();
if(currentDialogue == null)
{
Debug.Log("null");
continue;
}
for (int index = 0; index < currentDialogue.linkedDialogues.Count; index++ )
{
if (currentDialogue.linkedDialogues[index] != null)
{
Debug.Log(currentDialogue.linkedDialogues[index].name);
//ERROR IN THIS LINE BUT CAN ACCESS OBJECT WITH ABOVE LOG STATEMENT
queue.Enqueue(currentDialogue.linkedDialogues[index]);
}
}
nodes.Add(new DialogueNode(currentDialogue, this, nodes.Count + 1, new Rect(currentPosX, 20, 400, 0)));
currentPosX += 200.0f;
}