- Home /
Two GameObjects collide; only one OnCollisionEnter is triggered?
I have two game objects that are colliding (ball and wall) and both have rigidbody attached. Wall is kinematic, ball is non-kinematic. They collide OK and ball bounces OK.
My issue: While I have logic written in the OnCollisionEnter2D function on BOTH game objects, only the OnCollisionEnter2D on the wall gameObject gets triggered.
I thought that the OnCollisionEnter2D event would be triggered on ALL objects involved with the collider parameter each referencing the other gameObject's collider.
What gives?
Manny
Answer by redeemer · May 21, 2015 at 04:37 PM
It should fire both of them. I've made a simple example scene, you can get it here :
https://mega.co.nz/#!H8ElFBzT!d1JpixXbBajL_IM95Mu-IVk_RXsDs_SHZulOOUUONWE
Just import it in an empty project and hit play, you'll see it prints both Debug logs, maning it triggers both ball and floor (I've made with a floor instead a wall to get advantage of the gravity hehe, but the concept is the same, the floor is kinematic and the ball is not kinematic).
Agreed that it should fire both of them.. any ideas on why it's not?
I'd need more info to try to find the cause. Like the scripts your working with and the setup of your objects and project. Just guessing here...Did you change the physics layers matrix? Are you completely sure its not being fired in both scripts? Couldn't it be a "leak" in code?
I've put Debug.Log() in the OnCollisionEnter2D function in both my objects are are involved and only one of them is printed to console. The one that gets triggered is the kinematic object (i.e. wall).
I thought that maybe the event is getting consumed or canceled somehow but have been unable to see how.
I don't see how we can help you if you don't provide more info, sorry...
@manny003:
$$anonymous$$aybe you misspelled the method name? In your question title you said "OnCollisionEnter" and in your description you talk about "OnCollisionEnter2D". Those have nothing in common and are two completely unrelated callbacks. You said you have a "Rigidbody" attached. So do you use 3d physics(Rigidbody) or 2d physics(Rigidbody2D)?
Your answer
Follow this Question
Related Questions
Its not playing the Audio? 2 Answers
What does the word for mean in javascript? 1 Answer
How to access a non static variable by another static variable? 1 Answer
How does one declare a public variable without exposing it (in Javascript)? 0 Answers
Running script on multiple objects but script only runs once 2 Answers