- Home /
How to check the collision layer on collision event?
I'm sorry, I know this is basic stuff, but I can't find up to date answers ANYWHERE!!! :P
I have a collision event already set up, but it will fire for anything it collides with. I only want it to react to a specific collision layer. How do I do it?
Here's an answer from 2012, but it doesn't seem to work anymore: https://answers.unity.com/questions/261556/how-to-tell-if-my-character-hit-a-collider-of-a-ce.html
Answer by LCStark · Oct 04, 2018 at 07:09 PM
There's no reason it shouldn't work - the Collider
object still can access the GameObject
it is attached to and in turn its layer:
void OnCollisionEnter(Collision collision) {
Debug.Log(collision.collider.gameObject.layer);
}
Check if you have your layer set up on the
GameObject
that contains the collider component. Maybe you've set up the layer on a parent object and not its children?
Your answer

Follow this Question
Related Questions
Collision detection that ignores self but returns hits with other objects of the same layerMask 2 Answers
the most efficient way to detect colision between objects in a large scene (Strategy Game) 1 Answer
Adds too many points to the score? 0 Answers
My Javascript collision isn't being detected, please help. 0 Answers
Why isn't continuous collision detection working on terrain? 1 Answer