- Home /
object being called doesn't seem to be recognized
I am getting a null reference exception on the line after the one where I am making sure I am connected to the correct object. I used an if statement to make sure it is the correct object but then get a null reference exception on the following line.
void OnTriggerStay (Collider other) {
if(other.gameObject.name == "hand") {
Debug.Log (other.gameObject.GetComponent<PullChain>().chainGrabbed);
}
}
PullChain is the name of a script and chainGrabbed is a public bool. The script is attached to the hand object and I made sure to copy and past the name of the script and variable.
Answer by andyspeak · Jul 20, 2020 at 10:24 PM
your right that should work. so all i can do is list reason it wouldn't work
the object with the collider doesn't have the script your looking for
there is a rigidbody on a parent of the collider you think is the hand diverting collision events to it
the script is on a child of the hand try getComponentInChildren
the script is on a child of the hand try getComponentInParent
Ok, I really thought it was the code but having a second set of eyes makes me confident it is something in the scene instead. I will take a look at the items your suggested and anything related. Thank you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613003622im_/https://answers.unity.com/themes/thub/images/avi.jpg)