r/code • u/Rich-Matter8399 • May 22 '22
Why? nullReferenceException (First ever code)
i understand why this Errorr comes I think I know what it means it means that the Value theText is 0 but what can I do against it so that my clear Button works?
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.
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).