Trouble with Text field in the new ui

So I have a panel and to that panel iv’e attached a script that does basically this:

public Text myTextField;

Than in the inspector I dragged the Text element
Than in the update function I just do this:

myTextField.text = "tralalalala";

for some reason the console is giving me a NullReferenceException: Object reference not set to an instance of an object error

The thing is the text element is set in the inspector and its actually working as in the text changes to “tralalala”
Any ideas why the error?

You need to put:

using UnityEngine.UI;

At the top of your script.

I know it’s odd… it struck me as odd too … why have a using statement when we use so few of them and the UI is such a big part of the system? Whatever, it takes half a sec so it’s no biggy :slight_smile: Just gotta remember it.

Just because in 4.6 and 5 they are trying to namespace all the different parts of the system.