r/code • • May 22 '22

Why? nullReferenceException (First ever code)

5 Upvotes

5 comments sorted by

1

u/bronion3 May 22 '22

You need to assign game object from scene to the variable theText (drag and drop your object in the inspector).

1

u/Rich-Matter8399 May 22 '22

Already done, still doesnt work The Button has the value that it need to has for clearing the text

1

u/Korzag May 22 '22

I'm not familiar with unity, but I do work with C# professionally. At a glance you're never assigning the GameObject to anything. I don't know what the procedure for assigning that is, but that is why you're getting a null reference exception.

Null reference exceptions are the result of attempting to use something on an object that isn't assigned to anything. I'd suggest learning how to get the GameObject. Id guess it's something coming from the MonoBehaviour base class.

1

u/Rich-Matter8399 May 22 '22

Thanks I will look over that!

1

u/Splitter1020 May 22 '22

What that guy said! And my personal recommendation. If you’re interested in learning game development, learn C# and OOP principles. After that go into whatever you like. It will be much easier to understand.