Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by manny003 · May 21, 2015 at 02:38 PM · javascriptphysics2dscriptingbasics

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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).

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image manny003 · May 21, 2015 at 07:52 PM 0
Share

Agreed that it should fire both of them.. any ideas on why it's not?

avatar image redeemer · May 21, 2015 at 09:34 PM 0
Share

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?

avatar image manny003 · May 23, 2015 at 03:20 PM 0
Share

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.

avatar image redeemer · May 25, 2015 at 01:34 AM 1
Share

I don't see how we can help you if you don't provide more info, sorry...

avatar image Bunny83 · May 25, 2015 at 02:11 AM 0
Share

@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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges