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
1
Question by Sir-Irk · Jan 25, 2014 at 05:45 AM · collisioninstantiation

Check For Collision with anything in If-else

I haven't been able to find an answer for this as all google results are about OnCollisionEnter() and the like. I do not want it to check every update. I'm doing simple object placement based on the mouse position. When I click to place the object I want to run a check on some of its colliders to see if they are touching anything immediately after instantiation. In pseudo-code I want to do this

 If(collider is touching anything){
     Destroy(collider.gameObject);
 }
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
-1

Answer by getyour411 · Jan 25, 2014 at 06:47 AM

http://answers.unity3d.com/questions/41599/how-do-i-check-if-an-instantiated-object-collides.html

or Google: unity3d object collider instantiate for other examples

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 Sir-Irk · Jan 25, 2014 at 08:22 AM 0
Share

As I said in my question I would like to avoid using OnCollisionEnter as this would require me to make a separate script for the object with the collider. When the object gets instantiated I want to see if any of its children's colliders are colliding and if so destroy the child. It seems clumsy to use OnCollisionEnter() because I don't want it to check for collisions afterwards(it's just gonna be hit by a raycast). Thanks for your response

avatar image getyour411 · Jan 25, 2014 at 08:47 AM 0
Share

You can add the component via script, then remove it when you no longer need it. Are these children colliders actual Collisions, or triggers?

avatar image Sir-Irk · Feb 08, 2014 at 08:01 AM 0
Share

Sorry I haven't responded for some time. I wasn't able to work on my project for a week and almost forgot I posted this! I ended up solving my issue simply by using Bounds.Intersects() and a for() loop to iterate through all the objects in the level. I haven't done hardly any optimizations for it yet but this is the technique I was looking for. I was able to do this in a script on the parent object this way which is nice. It also only checks for collisions when it absolutely needs to. I knew I could do it all this way as I've done this in XNA before. I just wasn't sure if Unity had a different and/or better way to do it. Again, thanks for you help.

avatar image getyour411 · Feb 08, 2014 at 08:57 AM 0
Share

Bounds.Intersects() is a good solution, I keep forgetting about it as I haven't used it personally, but I see others recommend & reference it often as a good tool.

avatar image Ziplock9000 · Dec 23, 2020 at 04:04 PM 0
Share

That answer is not a test as the OP ask, it's an event.

avatar image
-1

Answer by BrandonHi · Aug 10, 2016 at 03:09 PM

Perhaps you could use OnCollisionEnter if you use time.deltatime and only execute OnCollisionEnter like one second after the instantiation. Sorry I was too busy to test it myself but it might work. I'm new too

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 Ziplock9000 · Dec 23, 2020 at 04:05 PM 0
Share

That answer is not a test as the OP ask, it's an event.

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

Check Collision In Editor Mode 2 Answers

Endless Runner Ground Issue 0 Answers

Linecast ignoring mesh collider 1 Answer

Collsion without ririgibody 1 Answer

Rigidbody MoveTo considering collisions 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