- Home /
NullReferenceException question.
void OnTriggerEnter(Collider collider)
{
if (collider.gameObject.tag == "bullet")
{
manager.SendMessage("Box",collider,SendMessageOptions.DontRequireReceiver);
}
}
Console says collider is a null reference. How come? All objects' colliders and triggers are enabled. How could an active collider be null? Thanks in advance.
Edit : My manager variable:
GameObject manager;
// Use this for initialization
void Start () {
manager = GameObject.Find("GameManager");
}
The only thing on the 5th line that can throw a NullReferenceException is the manager. Where do you set the value of the manager variable?
maybe its the manager object. make sure its not that one, because with that, I don't think we will be able to help much.
You should probably add some debug to the Start method to check that the manager actually gets a value after you have searched for it.
Answer by Nick4 · Jan 07, 2014 at 01:00 PM
Thanks, everyone. I got rid of it by simply assigning value to manager variable in Awake() method.
Answer by tanoshimi · Jan 07, 2014 at 11:22 AM
Because you've spelled it colllider.
Haha, I must have done it while trying to edit the question a few $$anonymous$$utes ago. Thanks for notifying though.