Error with AdventureGame.cs

Hello,

I’m having a problem with the AdventureGame.cs file after doing the challenge. I checked both the State.cs file and AdventureGame.cs file in the recourses and compared it to mine but they are the same.
I’m making use of Unity 2020 1.6f1.
The problem basically prevents me from progressing.

Hi Kederin,

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

NullReferenceException means that a reference (“link”) to an instance is missing. Double click on the error message to see to which line in your code it is referring. If you exposed a field in the Inspector, make sure that it’s not empty.

Hope this helps :slight_smile:


See also;

Thanks for replying,

But I still don’t seem to get the problem.
Unity is referring to line 18 in adventure.cs which is the following;
textComponent.text = state.GetStateStory();
As is said in the previous post I compared my files with the files in the recourses and they seem to be the exact same. I even copied both files from the recourses to mine to be sure I have the exact same.
It just seems to me that there is a problem in Unity and not within the C# files, but maybe I’m overlooking something.
Maybe I should try to use a different version of Unity and see if the same error will appear.
In Visual Studio there are no errors either.

Thanks in advance,
Kederin

Did you also check the Inspector of your Game game object in the Hierarchy? Take a look at the AdventureGame component. Is a Text object assigned to the “Text Component” field? Or does the field say “None”?

I think that did it. the “game” object in the hierarchy had no text object assigned to it. I assigned “storytext” in the Text component field and the error doesn’t show up anymore. before that the field said “none”

Thanks a lot Nina,
Kederin

You’re welcome. I’m glad the solution was so simple. :slight_smile:

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

Privacy & Terms