RaycastAll - does rigidbody on parent object interfere with hit-responses of child colliders?

I'm using the following bit of code (nearly verbatim from scripting resource). I think I may not be fully understanding the RaycastAll function. I'll have 2-4 "stacked" colliders and the script will show that hits.length = 2,3, or 4. However, I will only ever get the "top" collider's name or tag using the print statement.

function Update  () {

    var hits : RaycastHit[];
    hits = Physics.RaycastAll (camera.main.ScreenPointToRay(Input.mousePosition),Mathf.Infinity);

    for (var i=0;i<hits.length;i++)
    {
        var hit : RaycastHit = hits*;*
 *print(hit.transform.gameObject.tag);*
 *var renderer = hit.collider.renderer;*
 *if (renderer)*
 *{*
 *renderer.material.color.r += 0.35;*
 *renderer.material.color.g += 0.35;*
 *renderer.material.color.b += 0.35;*
 *}*
 *}*
*}*
*```*

As you've mentioned, adding a rigidbody to the parent sets hit.transform references to the object with the rigidbody

Fortunately, it doesn't change hit.collider - this means it'll work just as expected if you change to that

As to whether this should be the case, my guess is yes - transform gives you back the object you're usually interested in when you're responding to raycasts (i.e. the root object of the enemy, etc etc), and collider gives you back the specific collider

Edit:

http://unity3d.com/support/documentation/ScriptReference/Collision-transform.html

All documented, so not a bad guess (Though next time I check the docs sooner)

Maybe you could use

var output:string;
for(hit in hits)
{
output += hit.transform.gameObject.name + ", ";
}
print(output);

to see if it works.

It would be strange if the loop gets executed correct but not printed.

I had the same issue and turns out the child’s rigidbody was not being simulated, didn’t even had to change the code, I just turned simulated on in the game object’s inspector and it worked.