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 robert170 · Mar 07, 2014 at 08:39 PM · 2dupdateoncollisionentercollisiondetection

OnCollisionEnter2D Questions

If i have a rectangle 2d object and suddenly it overlaps 2 or more other objects at once, will the rectangle's "OnCollisionEnter2D" get called more than once in a single frame? I am instantiating a rectangular object in a game and it "might" overlap with more than one object when i instantiate it. Also, when does the "OnCollisionEnter2D" get called? Is it before Update function or after? Last, will "OnCollisionEnter2D" get called multiple times before or after the Update function? Thanks!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Stormizin · Mar 07, 2014 at 08:41 PM

Is called at the same time of Update.

Using a rigidbody will call once time only, till other gameObject collide.

Comment
Add comment · Show 1 · 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 robert170 · Mar 07, 2014 at 08:48 PM 0
Share

what do you mean by "same time" of update? they are different threads? i used box collider2d by the way.

avatar image
0

Answer by GameVortex · Mar 08, 2014 at 12:09 AM

In a single frame the Collision event will be called a maximum of one time for each object that has collided with it that frame. The collision event is called in the physics step which happens after Update, LateUpdate and FixedUpdate.

Comment
Add comment · Show 4 · 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 robert170 · Mar 08, 2014 at 12:15 AM 0
Share

So if it only gets called once,how do you know which object it collided with? also, does this get called before or after the update function?

avatar image GameVortex · Mar 08, 2014 at 12:26 AM 1
Share

As i said it gets called after Update. Not only once, but one time for each object. The collision event has the collider it collided with as a variable in the collision parameter. So you can check the name, the tag, the components or anything else to know which object it is.

avatar image robert170 · Mar 08, 2014 at 05:25 AM 0
Share

I see. So for example, if the rectangle object collided with 4 other objects called A, B, C, and D, the function call sequence would be "Update" -> "rectangle.OnCollisionEnter2D (A)" -> "rectangle.OnCollisionEnter2D (B)" -> "rectangle.OnCollisionEnter2D (C)" -> "rectangle.OnCollisionEnter2D (D)" .... next frame ... "Update" .. and so on.... correct? Or would the sequence might NOT be A, B, C, and D? Sorry for asking so many questions.. thanks.

avatar image GameVortex · Mar 08, 2014 at 09:48 AM 0
Share

That is correct, except that you have no guarantee of which sequence A, B, C and D will be in, but they will all happen after Update.

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

22 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 avatar image avatar image

Related Questions

OnCollisionEnter2D Questions 0 Answers

Testing for collisions prior to placing an object 0 Answers

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 1 Answer

Unity 2D Update Release (Tile Map)? 0 Answers

Handling Movement - Animations 1 Answer


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