Are you positive you don’t have any compiler errors in the console? Even one prevents EVERYTHING from working.
Make sure your log console selector buttons are enabled. See this graphic:
What @Joe-Censored means is this button in the upper right corner of your console window: make sure it is ON and does not show any errors:
(Same goes for Log, LogWarning, LogError, those three buttons)
[4239121--377296--errors.png]
Praetor is turbo-Praetor! But I wild add one more:
is your console log/logwarning/logerror buttons checked (upper right corner of log window)?
See here: I have 97 warnings and have abdicated my responsibility as a developer by turning them off:
[6215873--683432--Screen Shot 2020-08-17 at 3.55.25 PM.png]
Beyond that, as you already suspect, there is only one answer for ALL nullrefs.
The answer is always the same… ALWAYS. It is the single most common error ever.
Don’t waste your life spinning around and round on this error. Instead, learn how to fix it fast… it’s EASY!!
Some notes on how to fix a NullReferenceException error in Unity3D
also known as: Unassigned Reference Exception
also known as: Missing Reference Exception
also known as: Object reference not set to an instance of an object
http://plbm.com/?p=221
The basic steps outlined above are:
Identify what is null
Identify why it is null
Fix that.
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:
Let me take you step by step through it.
You see the error line, line 35?
The only possible thing that could be null in that line is audio_BGMusic
So that's part 1. That's what's null. We identified it.
Part 2... WHY is it null? Well, first we start with "who is supposed to make it not null?"
Looking up further I see line 19 sets it, with this construct:
audio_BGMusic = ObjectMusic.GetComponent<AudioSource>();
So lets take that apart. How can that fail? We have to suppose it DID fa…
Step by step, break it down, find the problem.
Here is a clean analogy of the actual underlying problem of a null reference exception:
Is your particle system assigned to the field in the Inspector on your script?
A Null Reference Exception (NRE) is caused when you’re trying to access a method or property on a null object – in other words, trying to get something from nothing.
Pretend I give you a set of instructions:
I will hand you a package of Oreos.
Open the package
Take out a cookie.
Eat the cookie.
Close the package.
I hand you the package, you open it, and the container is empty. Your “code” would fail at line 4, be…