I have a compound object. The parent of the compound object hierarchy has a script that is listening to the OnTrigerXXX callbacks of the children. When this compound object collides with other objects is there any way to get both colliders? I mean the "other" collider and the collider that belongs to the compound object itself that collided?
P.D: All rigid bodies must be kinematic, so, I can't use OnCollisionXXXX with the collision info param that has all the information I need in the contacts array.
Edit to add a bit more information as Savlon suggested:
When we are not using compound objects and we want to have a centralized place to handle children collision events, we could have something like this:
//In Children
void OnTriggerEnter(Collider c)
{
(parent's script).TriggerHandler(this, c);
}
//In Parent
public void TriggerHandler(GameObject theChild, Collider c)
{
// do stuff
}
This is ok and will work. The "problems" with this way are:
- I could have a lot of children, so, using compound objects I would need to add just a rigid body component to the parent. This could be a pretty good memory reduction usage. However if I don't use compound objects I will have to add a rigid body to every child like in the previous code.
- In my case children under a parent are always touching. Not intersecing but touching. Think about a set of blocks one beside the other. They do not intersect but there are no gaps between them. With compound objects I don't have to mess with it. It authomatically treats all the children as a whole and no collision callbacks will be fired among them.
On the other hand when using compund objects, you get all the advantages listed before but if you need information about what children collided with another collider you won't be able to get it because your script listening to callbacks is in the parent and you will only receive as parameter the "other" collider when unity calls you back through OnTriggerXXXX callback.
I was asking if there is any way to get both colliders using a compound object.
Hope everything is clearer now.
Cheers