I was doing some raycasting so I could interact with objects in my scene. If I happen to click on some of the background objects I get an error like
MissingComponentException: There is no 'Rigidbody' attached to the "fountain" game object, but a script is trying to access it.
probably because my code just calls
rb = hit.collider.gameobject.GetComponent<Rigidbody>();
This is perfectly sensible error message. Since many objects in the scene have no business having a Rigidbody component I think it silly to add one just to suppress this error. How do I test for the presence of a component on the object to avoid triggering the error?