- Home /
Getting UV coords of collider instead of parent.
Here's the situation: I have an object with a collider, which has a child that also has a collider (a mesh collider). I want to raycast and get the textureCoords from the child collider.
Now, the child collider is on a layer which the ray can detect, while the parent is not.
The RaycastHit however, still returns only the parent collider (expected behaviour, as this is done in order to give the ability to make one big collider, with multiple child colliders).
So I am getting no textureCoords output, as the collider has to be a mesh collider (the parent is not, changing the parent to a mesh collider did not fix the problem).
How can I get the raycastHit to reference the child instead of the parent?
Answer by Bunny83 · Aug 01, 2021 at 09:26 AM
Your question is confusing. You said you placed the colliders on seperate layers. If you do and specify the proper layer mask when doing the raycast you can only hit the specifed layers and all other layers are ignored. If that doesn't work for you, you probably did not specify the correct layermask. Keep in mind that the Raycast method requires a bit mask, not a layer index.
Apart from using Physics.Raycast you can also use Collider.Raycast if you know the collider beforehand. Note that Collider.Raycast will cast only against that collider. So it ignores everything else. This is actually better for performance, however you can not "shield" or block the raycast through other colliders of course. it's just like your collider is the only collider in the scene.
We don't know your exact application here. If you need / want to use Physics.Raycast it should work just fine when you use the correct layermask. Note that you need the corresponding bit in the layermask set to 1 if you want to be able to hit that layer. So a layermask of "0" would not hit anything, a value of 0xFFFFFFFF would include all layers (even the "ignore raycast layer") and a mask like 0x00000081 would only be able to hit layer "7" and layer "0"
Your answer
![](https://koobas.hobune.stream/wayback/20220613041018im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
OnCollisionEnter-issue 1 Answer
Enemy line of sight using linecast and colliders 1 Answer
Moving objects using raycasting? 1 Answer
Detecting whole gameobject, not just its collider 1 Answer
IsNormalized Error? 0 Answers