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 staticVoidMan · Sep 30, 2014 at 11:02 AM · collisionrigidbodypositionupdateaddforce

Destroy object on collision or check position

In the scenario where multiple rigidBodys moving due to addForce goes out of view (say, top of view) and is no longer needed then what technique should be prefered?

  1. Destroying the gameObject by detecting collision
    • by creating a collider object and destroying the rigidBody when it collides with it

  2. Destroying the gameObject by first checking it's rigidBody position in Update or FixedUpdate

Premature optimization or not, I'd still like to know
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
Best Answer

Answer by haim96 · Sep 30, 2014 at 11:24 AM

if you looking for optimization i would use object pool and avoid instantiate\destroy. for remove unused objects of the screen i would use collider set as trigger so you don't calculate collision physics and you don't need to check things every frame (or every X frames)

learn about object pooling:

http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-pooling

Comment
Add comment · Show 2 · 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 staticVoidMan · Oct 03, 2014 at 02:25 PM 0
Share

well, you technically suggested a 3rd way and... it looks like Object Pooling is THE way to go.

Thanks, I was anyways pretty doubtful on this Instantiate-Destroy thing.

avatar image haim96 · Oct 06, 2014 at 09:31 AM 0
Share

you welcome! :)

avatar image
0

Answer by GameVortex · Sep 30, 2014 at 11:33 AM

Both are perfectly valid methods. What is preferred is subjective and depends entirely on what works best for you and your game.

The first scenario has the issue that it will be calculating collision for all objects (which have colliders) which might not be the objects you need to destroy. This can easily be solved by putting the objects in the correct layer and modifying the collision matrix so the destroyer can only detect collision from the correct rigidbodies.

The second scenario is fine, you sort of get greater control of what specific objects will be checked, but could have issues if the objects are big and then might still be in view when their root position is not. There is also some complicated calculations to do if the camera is a perspective camera (the farther away the object is the higher up can it go before it is out of view). You could also get some issues if the camera can move around. All of these issues can be easily solved. Example: Having the camera in Orthographic mode (not applicable for all games), or not moving the camera at all, or never moving the objects in depth, or if you really want a perspective camera which moves around and the object should still be destroyed when out of view you could use OnBecameInvisible callback instead of checking positions.

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 staticVoidMan · Sep 30, 2014 at 12:21 PM 0
Share

For a fixed orthographic camera I'd go with OnBecameInvisible. Thanks. (Sorry, can't upvote since I don't have enough rep, for now)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Sphere vs Capsule collider collision resolution 0 Answers

jump on collision weird behaviour 2 Answers

Pick and move physics object 1 Answer

How can I apply a force to an object in the opposite direction of the object it's colliding with? 2 Answers

i want to make an animation throw code 0 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