• I have a LineRenderer that ignores certain Layers based on a Raycast using LayerMask.

  • I have a cube with a collider on a Layer which is ignored because of the LayerMask.

  • I have a smaller object inside the cube that is a child object of the cube and is on a layer that is not set to be ignored. I need the Raycast to hit the smaller object.

When this smaller object is un-parented from the larger cube, the LineRenderer behaves like I want it to: the hit data informs me it is being hit by the Raycast, but this does not hold true if the smaller object is a child of the cube.

Is there a way of having this behaviour without having to un-parent the smaller object? It's like the smaller object is inheriting the parent's Layer, despite being on it's own Layer - does this sound like what is happening?

  • 1
    \$\begingroup\$ It sounds like something else is going on. Parent/child relationships between GameObjects has no bearing on raycasts on its own. The only things that such relationships affect are transformation and active state (plus some utility stuff, like broadcasting messages, finding components, optionally changing layer assignments in the editor after prompting the user, etc.) \$\endgroup\$
    – Ed Marty
    Sep 14, 2017 at 12:31

1 Answer 1


The Raycast was actually hitting the child object but returning data for the parent object. It is possible however to return information about the child by accessing the collider that was hit (that of the child object).

So to access the child collider:


instead of just:


You can then access the gameObject, transform or whatever from the collider.

From the Unity docs for RaycastHit.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .