NullReferenceException: Object reference not set to an instance of an object

Hello! I’m following an online tutorial for setting up a visual novel. I only started using Unity yesterday (complete beginner…) and I got most of the steps to work, but I received this error near the end:

NullReferenceException: Object reference not set to an instance of an object DialogueManager.Start () (at Assets/Scripts/DialogueManager.cs:29)

The tutorial I’m following is here: Indiana University Bloomington

This is where the code is going wrong:

	parser = GameObject.Find("DialogueParser").GetComponent<DialogueParser>();

These are the codes I’m using:

using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;

public class DialogueParser : MonoBehaviour {

    struct DialogueLine {
        public string name;
        public string content;
        public int pose;
        public string position;
        public string[] options;

        public DialogueLine(string Name, string Content, int Pose, string Position) {
            name = Name;
            content = Content;
            pose = Pose;
            position = Position;
            options = new string[0];
        }
    }

    List<DialogueLine> lines;

    // Use this for initialization
    void Start () {
        string file = "Assets/Data/Dialogue";
        string sceneNum = EditorApplication.currentScene;
        sceneNum = Regex.Replace (sceneNum, "[^0-9]", "");
        file += sceneNum;
        file += ".txt";

        lines = new List<DialogueLine>();

        LoadDialogue (file);
    }

    // Update is called once per frame
    void Update () {

    }

    void LoadDialogue(string filename) {
        string line;
        StreamReader r = new StreamReader (filename);

        using (r) {
            do {
                line = r.ReadLine();
                if (line != null) {
                    string[] lineData = line.Split(';');
                    if (lineData[0] == "Player") {
                        DialogueLine lineEntry = new DialogueLine(lineData[0], "", 0, "");
                        lineEntry.options = new string[lineData.Length-1];
                        for (int i = 1; i < lineData.Length; i++) {
                            lineEntry.options[i-1] = lineData*;*

}
lines.Add(lineEntry);
} else {
DialogueLine lineEntry = new DialogueLine(lineData[0], lineData[1], int.Parse(lineData[2]), lineData[3]);
lines.Add(lineEntry);
}
}
}
while (line != null);
r.Close();
}
}

public string GetPosition(int lineNumber) {
if (lineNumber < lines.Count) {
return lines[lineNumber].position;
}
return “”;
}

public string GetName(int lineNumber) {
if (lineNumber < lines.Count) {
return lines[lineNumber].name;
}
return “”;
}

public string GetContent(int lineNumber) {
if (lineNumber < lines.Count) {
return lines[lineNumber].content;
}
return “”;
}

public int GetPose(int lineNumber) {
if (lineNumber < lines.Count) {
return lines[lineNumber].pose;
}
return 0;
}

public string[] GetOptions(int lineNumber) {
if (lineNumber < lines.Count) {
return lines[lineNumber].options;
}
return new string[0];
}
}
This is the code for the Dialogue Parser,
Next is the code for the Dialogue Manager,
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;

public class DialogueManager : MonoBehaviour {

DialogueParser parser;

public string dialogue, characterName;
public int lineNum;
int pose;
string position;
string[] options;
public bool playerTalking;
List buttons = new List ();

public Text dialogueBox;
public Text nameBox;
public GameObject choiceBox;

// Use this for initialization
void Start () {
dialogue = “”;
characterName = “”;
pose = 0;
position = “L”;
playerTalking = false;
parser = GameObject.Find(“DialogueParser”).GetComponent();
lineNum = 0;
}

// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (0) && playerTalking == false) {
ShowDialogue();

lineNum++;
}

UpdateUI ();
}

public void ShowDialogue() {
ResetImages ();
ParseLine ();
}

void UpdateUI() {
if (!playerTalking) {
ClearButtons();
}
dialogueBox.text = dialogue;
nameBox.text = characterName;
}

void ClearButtons() {
for (int i = 0; i < buttons.Count; i++) {
print (“Clearing buttons”);
Button b = buttons*;*
buttons.Remove(b);
Destroy(b.gameObject);
}
}

void ParseLine() {
if (parser.GetName (lineNum) != “Player”) {
playerTalking = false;
characterName = parser.GetName (lineNum);
dialogue = parser.GetContent (lineNum);
pose = parser.GetPose (lineNum);
position = parser.GetPosition (lineNum);
DisplayImages();
} else {
playerTalking = true;
characterName = “”;
dialogue = “”;
pose = 0;
position = “”;
options = parser.GetOptions(lineNum);
CreateButtons();
}
}

void CreateButtons() {
for (int i = 0; i < options.Length; i++) {
GameObject button = (GameObject)Instantiate(choiceBox);
Button b = button.GetComponent();
ChoiceButton cb = button.GetComponent();
cb.SetText(options*.Split(‘:’)[0]);*
cb.option = options*.Split(‘:’)[1];*
cb.box = this;
b.transform.SetParent(this.transform);
b.transform.localPosition = new Vector3(0,-25 + (i*50));
b.transform.localScale = new Vector3(1, 1, 1);
buttons.Add (b);
}
}

void ResetImages() {
if (characterName != “”) {
GameObject character = GameObject.Find (characterName);
SpriteRenderer currSprite = character.GetComponent();
currSprite.sprite = null;
}
}

void DisplayImages() {
if (characterName != “”) {
GameObject character = GameObject.Find(characterName);

SetSpritePositions(character);

SpriteRenderer currSprite = character.GetComponent();
currSprite.sprite = character.GetComponent().characterPoses[pose];
}
}

void SetSpritePositions(GameObject spriteObj) {
if (position == “L”) {
spriteObj.transform.position = new Vector3 (-6, 0);
} else if (position == “R”) {
spriteObj.transform.position = new Vector3 (6, 0);
}
spriteObj.transform.position = new Vector3 (spriteObj.transform.position.x, spriteObj.transform.position.y, 0);
}
}
I don’t even know if I’m giving the right information, honestly…
In the tutorial, it says that at this part the characters should pop up in the game, but they’re nowhere to be seen? I tried dragging them into the scene, and still nothing. The order layers are sorted correctly (With canvas set to -1 and my Character set to 1)
Can anyone help me with this problem??
Sorry if it’s very confusing…I’m a total beginner ^^;;

I cant see exactly what is not being set as I cant see inside your editor but Make sure your object is named exactly DialogueParser and that there is a component called DialogueParser on it, if there is no DialogueParser component - re-look at the tutorial and make sure you are referencing the right thing. If you make any progress post back and we can fight it together.

I think this should be correct as far as naming convention goes? After I reloaded the program, the nullreferenceexception error was gone, but my characters still aren’t showing up!

I’ll also include an image of my character box: