- Home /
I've miss explained my question. I will open a new one tomorrow that explains what I'm asking in better detail sorry for any inconvienice
Do Child Objects Trigger Parent Objects?
Short and sweet question. I've tried to look it up but I can't find it any where.
if you got this script
function OnTriggerEnter(){
print("ouch");
}
on a parent object, and the child is triggered, will the parents script respond?
are there any places to find this information out.
I think that might be whats going on with my current code but i can't be sure its not something else.
I dont think the parent will respond on child's trigger collision. If you want the parent to know, that the child is colliding with something, maybe you shoud add a script to the child, that will tell to the parent, that it has something in it's trigger area
Well I want the parent not to know but I'm basically making a punching game and when I triggered the child object with a punch, the parent object printed ouch. It could be something else but from my observation it seems as thought the parent responded to the child.
note I only have this script on the parent, before anyone asks.
does your parent also have this script attached to it ? i presume the parent also has collision box's. have u tried debugging to see if the script does run twice ? Also be carefull to make sure your coliders are not overlapping
Okay I just said that my parent is the only one with the script attached.
yes my parent has a collision box
no my colliders are not overlapping
they are not triggering each other!!!
please look at my comment on big bat's answer to see what I was asking.
Answer by bigbat · Jul 17, 2013 at 09:05 PM
If you have Colliders in parent and child objects, you could prevent their collider from undesired triggering each other by using "IsChildOf" function of their Transform component.See this snippet code from unity documentation:
function OnTriggerEnter (col : Collider) {
// Ignore trigger events if between this collider and colliders in children
// i.e. when you have a complex character with multiple triggers colliders.
if (col.transform.IsChildOf(transform))
return;
print("Do something here");
}
where transform refer to Transform component of parent object.
No, see, imagine I have a big cube that has lots of other little cubes spinning around it. The cubes are children of the big cube so when it moves the little cubes move too. when I punch the cube it should explode. i have the explosion script on the big cube
what's happening in my scene is i'm punching the little cubes (that don't have a script attachted to them yet) and the big cube is exploding.
it isn't really a cube thing but I just said that to give you an idea of whats happening.
i don't need to stop them from colliding with each other.
I JUST WANT TO $$anonymous$$NOW IF TRIGGERING A CHILD WILL TRIGGER A PARENT AS WELL!!!!!
on a side note thanks for answering but that's not my problem I guess I should have been more clear with my question.
the simplest answer to your question is no, the trigger of one event wont fire the event of another.
now i think we are still all confused as to how u have this setup. if you want your childs to trigger then they need there own onTrigger events and there own colision box's, im unsure why your parent has the script that the children will use.
p.s. we are trying to help, if we misunderstand your question, du to the lack of example code, please dont get frustrated with us. some ppl might only glance and give advise.
no I'm sorry its my fault. I sorry if it seemed like i was aggravated. thank you for answering my question it must be something else that is causing my problem. I closed the question because I wasn't clear enough. again my fault. sorry.
due the fact that you have just answered my question I will not be posting another one tomorrow
no worries, and just to re clarify. triggers dont care what object its attached to or what its parent is. they only care if a coliider mesh is present and touched, at this point the object its connected to will only will get the notification as a Event if a script is attached.
also think of it this way, i parent objects in scene for sake of sanity and logic, almost everything has a parent in my scenes, top parent is objLevel, and if i had to manually setup something so that parents dont get notified it would be way to long.