Question by
Brently15 · Jun 24, 2016 at 05:06 AM ·
c#unity 5instanceobject referenceobject-reference-error
Why is object reference not set to an instance?
private Text text;
private LyricList lineList = new LyricList();
private InputField inputField;
private string newState;
// Use this for initialization
void Start () {
// Get the text child object from the Canvas
text = gameObject.GetComponentInChildren<Text> ();
// Get the input field child object from the Canvas
inputField = gameObject.GetComponentInChildren<InputField> ();
//CreateAssetMenuAttribute our Lyric List
lineList.CreateList ();
text.text = "Please reassemble the song lyrics!\n" + instructions + "\n\nStart guessing to begin!\n\n";
}
Here is a snippet of my code. I am receiving an error on the text.text line saying "Object reference not set to an instance of an object." Any help would be appreciated.
Comment
Answer by JedBeryll · Jun 24, 2016 at 06:02 AM
Is it inactive? text = gameObject.GetComponentInChildren<Text> (true);
this would find it if it is. Also Start() isn't the best for setting up references. Try Awake() instead.
Unless I did Awake() wrong, neither of those worked. I appreciate the try though! Anymore suggestions?