- Home /
Question by
Woodpig · Jul 02, 2017 at 08:46 PM ·
respawnenablerespawningenable and disable script
(Solved!) OnEnable spams error messages
I'm using Void OnEnable () to reset some values when respawning enemies. It works perfectly except for the error messages that keeps spamming my console.
Here's an example:
void OnEnable ()
{
spotted = false;
activated = false;
isGrounded = false;
myRigidbody.gravityScale = 0f;
anim.SetBool ("Activated", false);
}
As soon as I press play, I get a bunch of error messages stating the following:
"NullReferenceException: Object reference not set to an instant of an object"
I need to tell my enemy that he hasn't already seen the player (when respawned) etc. So, how do I get around this? Would be very grateful for an answer.
Comment
Best Answer
Answer by ShadyProductions · Jul 02, 2017 at 08:55 PM
Either myRigidbody is null and does not exist or anim is null and does not exist.
You can fix this by adding checks:
if (myRigidbody != null)
myRigidbody.gravityScale = 0f;
if (anim != null)
anim.SetBool ("Activated", false);