- Home /
Why does Layer Masking for Raycasts only work on Layer 8?
Unity refuses to properly mask raycasts for any user layer other than 8. I use this code
int layerMask = 1<<8; int layerMask2 = 1<<9;
When I test both, the first one works fine against layer 8 objects, the second collides with none. Why?
$$anonymous$$y raycasts also work fine to pick out layers 9+. It's probably something else, in the code or set-up. Raycasts by themselves are a little tricky, and adding layermasks doesn't help (but, so far, 1<<9
is correct.)
Answer by Bunny83 · Oct 06, 2014 at 03:17 PM
Sorry, but this question is pointless in it's current form. I can assure you that the Raycast is working as intended. If it doesn't work for you, you might have something wrong. Either your raycasting code or your scene setup. Since you didn't provide any of that information in your question there's nothing we can do for you here.
Just a quick checklist:
Are you sure that the actual colliders you want to raycast against are on layer 9?
Are you sure your raycast actually can hit those colliders?
Are you sure the gameobjects are active?
Your answer
Follow this Question
Related Questions
Layer Mask Not working to open the door 1 Answer
Can't Make Raycast Ignore a Layer 3 Answers
How do I tell what NavMeshLayer a NavMeshAgent is currently on? 0 Answers
How to make my raycast also hit deactive objects WITHOUT showing the object? 1 Answer
Unable to set collision layer from scrip 0 Answers