Any time I apply the Detonator script to an object and try to make it explode, I get a null reference exception on line 159.
Is there anything wrong with it?
Any time I apply the Detonator script to an object and try to make it explode, I get a null reference exception on line 159.
Is there anything wrong with it?
What is MyDetonator()? Could it be returning null at line 159? Maybe try checking if(MyDetonator() == null)
at that point.
Did you mean write that in somewhere? I started learning code about a week ago, so I’m feeling pretty stupid right now.
No worries, everyone starts somewhere.
The error you’re getting, a null reference exception, means you’re trying to use a piece of memory that actually isn’t what you think it is. It’s assigned to null – nothingness. I get the feeling that MyDetonator() is actually returning null, and you’re running into trouble when you try to use it at line 159.
You can do something like this just before that line to test if MyDetonator() is returning null or not:
if(MyDetonator() == null)
{
Debug.Log("Hey, MyDetonator is null!");
} else {
Debug.Log("MyDetonator isn't null, so that's not the problem.");
}
Ah, gotcha.
It returned MyDetonator isn’t null, so that’s not the problem.
Detonator uses internal calls to Camera.main which will fail if your camera isn’t tagged as MainCamera and throws nulls all over. This might be your issue.
http://docs.unity3d.com/Documentation/ScriptReference/Camera-main.html
I tried that fix as well, it didn’t prevent the error : /
Are you able to upload your project so I can take a closer look?