NullReferenceException error?

I was getting that error message too. Now I can get it to work the first time I press the 1 key and the first time I press the 2 key but it won’t continue. It will freeze after that no matter what I press.

Any errors in the console Penny?

Yes.

Sorry, overlapping conversations in the same topic here…

Ok, so what is the code on line 44 Penny?

I’m waiting for Visual Studio to load it so I can find line 44 but while I’m waiting on that, can you tell from this image of the Inspector which line it might be?

…not without counting all the lines of text, no… made even more challenging by them not all being visible :slight_smile:

Hi,

Ok thanks… btw you can just copy/paste your code into the posts on the forum, make it easier sometimes for those helping to copy/paste chunks back to you with a fix :slight_smile:

So, your error message is stating that you are trying to access an array but the index you are using is out of the bounds of that array. In more straightforward speak, you are using an index value that is larger than the array.

Specifically;

nextStates[2]

This would indicate that the number of states returned for the current state isn’t 3. Perhaps take a look at the scriptable object for the state in question and see if you have missed adding one of the next states to it.

Hope this helps :slight_smile:


See also;

I was following the instructions of the instructor (forgot his name – I’m not good with names) but I was confused as to why he said to put that 3 in there. Did he tell us wrong?

His name is Rick.

The 3 is the size of the array and indicates the number of elements it has. Arrays are zero-based meaning that the index of the elements starts at 0. Thus, the three elements would have indexes of 0, 1 and 2.

If you try to access the array with an index larger than its number of elements you will see the error you received.

1 Like

Yeah! It’s working now!

Thanks so much for your help!

1 Like

You’re very welcome. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms