,Hi guys. Wrote a method which find highest gameObject parent with Rigidbody.
public Rigidbody RecursiveReturnRigidbodyParent(GameObject gameObjectGrabed)
{
while (gameObjectGrabed.GetComponentInParent<Rigidbody>())
{
gameObjectGrabed = gameObjectGrabed.transform.parent.gameObject;
}
return gameObjectGrabed.GetComponent<Rigidbody>();
}
Aaand thats the problem:
NullReferenceException: Object reference not set to an instance of an object
Im grabbing object using raycast. If the object contains rigidbody then it search further if any of the parent object have rigidbody.