Can not access GetComponentInParent < Rigidbody > ( ). usegravity

Hi i have 2 gameobjects Parent and Child. Child has a script when OnCollisionEnter with a wall it will call GetComponentInParent < Rigidbody > ( ). usegravity and set it to true. Whenever i run it the game the gravity seems to switch in the child not in the parent what i am doing wrong ? all of the objects have Rigidbodies and Colliders.


//Script attached to the child.

void OnCollisionEnter(Collision other) 

 GetComponentInParent < Rigidbody > ( ). usegravity = true;


If i want to access a script in the parent then GetComponentInParent < Parent Script > ( ) ; works with no problem.

The documentation for GetComponentInParent states:

Returns the component of Type type in
the GameObject or any of its parents.

So the function will look for the component in the current object first and only look in the parent if it’s not found. I assume your child object has a Rigidbody. You can use transform.parent.GetComponent to look just in the parent.