Newb Question: Can't find collider of Rigidbody

I’m pretty new to Unity and I’ve been trying to debug a question for hours.

I created a “player” prefab in editor and assigned it a rigidbody. I then attached a “weapon” prefab in a script and added it as a child to “player”. I then created a “bullet” object in script, also rigidbody in the manner of the fps tutorial. I want to make sure the bullet doesn’t collide with the player. However, when I try to call:

Physics.IgnoreCollision(newBullet.collider, transform.root.collider);

I get the following error:
“MissingComponentException: There is no ‘Collider’ attached to the “player” game object, but a script is trying to access it.”

I’ve been looking for hours to see what I could’ve done wrong. From my understanding, a rigidbody would have a collider object right? All the child objects of my prefab have collider objects. I assumed there would be a compound collider on the rigidbody created that would catch collisions. Do I have to create some sort of an object on the player? Any help would be greatly appreciated!

The main question for you to answer is, where in the player prefab is the collider. transform.root brings you to the root of all game object, so I doubt that this is what you want. Instead, I assume that the collider is in a child of the transform, which means you can use GetComponent or GetComponentInChildren.

Thanks for the reply Dantus. I’m guess I’m not understanding the prefab model very well. I attached a rigidbody to the prefab object and have basic colliders for its children, the head, torso and such. I assumed that I could refer to the parent prefab GameObject and get the collider of it. I thought that a rigidbody would create a compound collider or something by default. Should I be referencing the colliders of individual children?

If you need to access some specific colliders, it makes indeed sense to have a variable directly in the inspector, such that you can be sure to have the right one.