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

As I stated in my previous question, I’m trying to code something similar to this to tell the story in my game.

Now, I can make a single, pre-specified line and speaker’s name work just fine with the code I had, but telling a story that way obviously required for me to use a file to store the strings to pull from.

So I did this.

I saw no problems with it, nor were there any errors caught, but when I tried to run it:

NullReferenceException: Object reference not set to an instance of an object
VisualNovelScript.Update () (at Assets/VisualNovelScript.cs:21)

For the record, that line is:

if (lines[lineNum].StartsWith(“>”)){

I have no idea how to remove this error. Could someone please explain what I’m doing wrong?

Add that after you initialize line in Start function (line 15) :

for( int i = 0; i < lines.Length; i++ ){
print(i);
print(lines*);*
}
I suspect there is a null one in there, that way you’ll be able to find which one. Maybe ScriptFile.text.Split doesn’t do what it’s supposed to do ?

it is simple you are trying to access the lineNum -th item of lines array. but lineNum-th item never exists!! try printing the lines.Length and also lineNum … Im sure that will expain you the problem.

print(lines.Length+"   "+lineNum);