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 BarnsChambers · Jan 09, 2014 at 02:45 PM · collisionerrorparentchild

Child Object OnCollisionEnter Effecting it's Parent + Sibling Objects

Hey guys thanks for reading.

I have a wall, the wall is made up of bricks. All these bricks are stored in a "Wall" empty gameObject . When my bullet hit's a brick, I would like only the brick it collided with to be setActive(false); however for some reason the parent of this object is also being setActive(false); along with all other brick sibling objects.

This does not happen when it is not a child of the "Wall" gameObject, but it is not possible for me to not have this parent, for other reasons in the game.

I have tried using:

  void OnCollisionEnter(Collision other){
                 other.gameObject.transform.parent = null;  
       }

but this also did not work. I am COMPLETELY stumped :(. Any ideas? Here is my code.

  void OnCollisionEnter(Collision other){

     
     if(other.collider.transform.tag == "Cube"){
         
 
         other.gameObject.SetActive(false);
         
     }
     
 }
Comment
Add comment · Show 1
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 semiessessi · Jan 09, 2014 at 04:36 PM 0
Share

this might sound stupid or condescending but 'try debugging it'. there is a ton of information absent here which tells me you either haven't debugged this or need some instruction on what debugging is and how to do it.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by TimBorquez · Jan 09, 2014 at 04:27 PM

do those bricks have rigidbodies?

also maybe try:

 other.collider.gameObject.SetActive(false);


untested, but that code should access the gameobject with the collider because just gameobject is likely too vague and thats why you get the parent because technically it is the gameobject you're hitting

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 BarnsChambers · Jan 11, 2014 at 08:31 AM 0
Share

Only the parent has a rigidbody, and the problem is resolved if the rigidbody on the parent is removed (although it needs to have a rigidbody for other code to work)

I think it's wrapping the WHOLE parent+children objects in the rigidbody so it things the parent should be destroyed, which is not desired.

Still not sure how to fix this.

avatar image
0

Answer by Kolodej · Jan 09, 2014 at 04:59 PM

Hi, are the wall components (bricks) named "Cube"? If yes, then look for a chain reaction between bricks. I am just guessing. You will see, if you insert debug output into CollisionEnter callback.

Comment
Add comment · 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

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

21 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

Related Questions

Make a simple tree 1 Answer

OnCollisionEnter not registering on children 0 Answers

How to detect child object collisions on parent 3 Answers

How to destroy a parent object when child object is collided 1 Answer

Javascript Detecting a prefab's child's collision 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