Object reference not set to an instance of an object

I’m very new to unity and don’t understand why I get this error, in the unity editor I have an gameobject which contains this script as a component, I attached the UI-text to the script in the component but it just shows the error and the text doesn’t change.

using UnityEngine.UI;

public class GlobalScore : MonoBehaviour
{

    public GameObject ScoreDisplay;
    private void Update()
    {
        ScoreDisplay.GetComponent<Text>().text = "SCORE: ";
    }
}

Its probably an easy fix but any help is appreciated

Take a look at this post its pinned to the top of the scripting forum: https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

1 Like

thanks, ill look into that