I was making a health system and I got this error :
NullReferenceException: Object reference not set to an instance of an object
This was the code that I made which broke the animator:
Now, whenever I go onto the animator window on any game object, it gives out that error and there is nothing in the animator. I searched for any solutions but nothing seemed to help.
can you paste the objects inspector showing it has an animator and this script on it?
thanks for trying to help but it just kind of fixed itself when I relaunched the project for the third time lol
do you have hotreload or something?
There’s a million and one ways to get this error in every single part of any piece of code.
It can be in your code, in Unity’s package code, or anywhere else.
Fortunately it does not require posting, and posting won’t fix it either.
The answer to fix it 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:
http://plbm.com/?p=221