Please help, Object reference not set to an instance of an object

I been stuck on this part for a while. When I have to run the project to see if it works, after I set a return to game object Unity keeps giving me this error: NullReferenceException: Object reference not set to an instance of an object
AdventureGame.Start () (at Assets/AdventureGame.cs:17)

/  
   [SerializeField] Text textComponent;
   [SerializeField] State startingState;

    State state; 

    // Use this for initialization
    void Start () {

        state = startingState;
        textComponent.text = state.GetStateStory();

    }  


/  
    [TextArea (10,14)] [SerializeField] string storyText;

    public string GetStateStory()

    {
        return storyText; 

    }  

I been trying all I could, even rewriting specific parts to see if maybe there was a misstype I dint notice, but to no avail.

1 Like

Hi,

NullReferenceException means that a reference (“link”) to an instance is missing. If you exposed a field in the Inspector, make sure that it’s not empty.

1 Like

Thanks very much, I dint catch what I was missing at first, but thanks to your advice I was able to, I just had to watch the video again to catch on what was not assigned correctly.

Awesome. NullReferenceExceptions are one of the most common error messages. The earlier you encounter them and learn how to fix them, the better. :slight_smile:

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

Privacy & Terms