- Home /
Why do I get this error in such a simple script?
void OnTriggerEnter(Collider other) {
other.attachedRigidbody.AddForce (0, 5, 0);
}
Error: NullReferenceException: Object reference not set to an instance of an object CyclonePushUp.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/CyclonePushUp.cs:18)
Doesnt make sense. IT has a rigidbody and a collider :/. Thanks in advance
Answer by tanoshimi · May 22, 2015 at 10:58 AM
I suggest you Debug.Log(other.gameObject.name); to make sure it's colliding with the thing you think it is.
Answer by Priyanshu · May 22, 2015 at 11:06 AM
Doesnt make sense. IT has a rigidbody and a collider :/.
I guess you are talking about the object on which the script is attached to.
This error occurs when there is no RigidBody attached to other Object. Attach Rigidbody to the Object you are colliding with the script Object.
Answer by ShabihDesperado · May 22, 2015 at 11:09 AM
You are not checking that "other" is the correct object. Maybe there's another object with a collider there.