- Home /
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);
}
}
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.
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
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.
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.