NullReferenceException: Object reference not set to an instance of an object

I need to ask because i dont get it, why does this code throw an NullReferenceException: Object reference not set to an instance of an object?

error

Hi,

NullReferenceException means that a reference (“link”) to an instance is missing. Double click on the error message to see to which line in your code it is referring. If you exposed a field in the Inspector, make sure that it’s not empty.

Did this help?


See also:

the error is at playerhealth.TakeDamage(damage), and i am getting the reference at start function, or at least i think so

Is there a Health component attached to the same game object as the EnemyAttack component? If not, GetComponent always returns null.

I think i had the health comboment attached but im not sure, if there was a health comboment is there a possible for something else to be the problem? If no then i probably didnt add it

The best would be to check if you have a Health component attached. If Unity is already running, it should not take you longer than 2-3 seconds. Checking is more efficient than guessing around for hours or days. :wink:

i would but i swapped with the videos solution 2 days ago thats why i dont rememper :stuck_out_tongue:

Does that mean the problem is solved? :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms