Group Group Group Group Group Group Group Group Group

Object reference not set to an instance of an object in alienScript.GetDeathParticles().SetDeathFloor(deathFloor);

Hi, I am following the code from book but getting this error

Object reference not set to an instance of an object in alienScript.GetDeathParticles().SetDeathFloor(deathFloor);

please help!!!

I solved this one myself…thanks anyways…

Hey there, I’m getting the exact same error and have gone line by line through the book and I am typing everything in correctly. How did you manage to solve this on your own?

I’m afraid I don’t understand enough about the line “alienScript.GetDeathParticles().SetDeathFloor(deathFloor);” to troubleshoot this. The book doesn’t make it clear what this line is doing either.

Please help!

Hi Bud,

The problem was not with the coding, it was with the inspector.

From what I have understood, object reference can’t find instance of an object- error when it can’t find something(Game Object) attached to it.

Hope this helps!

Kunal

Hey there,

I couldn’t figure it out - I went through the inspector but couldn’t find anything deviant from the book. In the end, I loaded the RW supplied example completed project and that fixed it. Although even with that loaded I got another “object reference can’t find instance of an object” error on gun.cs - so not sure what is going on here.

This error normally comes when the components are not attached to game objects. I am no hot shot unity as well but have resolved this error twice by checking my inspector values. Can you copy and paste snipshot of your inspector?

I had the exact same issue. What I found was that I missed this:

“In the Project view, expand the Alien prefab and select the AlienDeathParticles GameObject. Click Add Component and under scripts, choose DeathParticles.”

I could have sworn I did that step, but maybe I did it to the alien in the scene prior to deleting him, and I forgot to apply it to the prefab.