Through the debug.log I was able to identify that the burningRecipeSO is the one that is null. but now I don’t know how to correct it so that error goes away. pls help.
The answer is always the same… ALWAYS!
How to fix a NullReferenceException error
Three steps to success:
- Identify what is null ← any other action taken before this step is WASTED TIME
- Identify why it is null
- Fix that
NullReference is the single most common error while programming. Fixing it is always the same.
Some notes on how to fix a NullReferenceException error in Unity3D:
Expect to see this error a LOT. It’s easily the most common thing to do when working. Learn how to fix it rapidly. It’s easy. See the above link for more tips.
You need to figure out HOW that variable is supposed to get its initial value. There are many ways in Unity. In order of likelihood, it might be ONE of the following:
- drag it in using the inspector
- code inside this script initializes it
- some OTHER external code initializes it
- ? something else?
This is the kind of mindset and thinking process you need to bring to this problem:
Step by step, break it down, find the problem.
I noticed that there is a word “tutorial” in the file name of attached code image. So I did a Google for “burningRecipeSO” and came across the following site.
Now I understand it is probably a trouble you encountered while learning about Unity while watching the above site and Youtube video created by the author of this tutorial.
(When you ask a question, you should also provide information like above, because there are too few clues and no one will be able to answer.)
I have NOT looked at the code directly because apparently I have to log-in to download the project file (I don’t really want to create an account …), but from the Youtube, it seems to be treated as a SerializedField.
So, I’m assuming that you have to set something against burningRecipeSO from outside of the StoveCounter.cs.
Based on the information up to the above, I guess that it is most likely “null” because you forgot to set some object by dragging and dropping it with the mouse at burningRecipeSO for StoveCounter in the “Inspector” tab. You might need to check again this point.
