Skip to main content
Tweeted twitter.com/#!/StackGameDev/status/538893750949646336
added 1457 characters in body
Source Link
Notbad
  • 1.1k
  • 2
  • 19
  • 31

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:

  1. I could have a lot of children, so, havingusing compound objects I would need to add just a rigid body component into the parent. This could be a pretty good memory reduction usage. However if I woulddon't use compound objects I will have to add a rigid body to every child if I decide to do things like in the previous code.
  2. 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 getreceive as parameter the "other" collider when unity calls you a OnTriggerXXXXback 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

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:

  1. I could have a lot of children, so, having just a rigid body component in the parent could be a pretty good memory reduction. I would have to add a rigid body to every child if I decide to do things like in the previous code.
  2. 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 you will only get the "other" collider when unity calls you a OnTriggerXXXX callback.

I was asking if there is any way to get both using a compound object.

Hope everything is clearer now.

Cheers

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:

  1. 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.
  2. 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

added 1457 characters in body
Source Link
Notbad
  • 1.1k
  • 2
  • 19
  • 31

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:

  1. I could have a lot of children, so, having just a rigid body component in the parent could be a pretty good memory reduction. I would have to add a rigid body to every child if I decide to do things like in the previous code.
  2. 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 you will only get the "other" collider when unity calls you a OnTriggerXXXX callback.

I was asking if there is any way to get both using a compound object.

Hope everything is clearer now.

Cheers

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.

Cheers

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:

  1. I could have a lot of children, so, having just a rigid body component in the parent could be a pretty good memory reduction. I would have to add a rigid body to every child if I decide to do things like in the previous code.
  2. 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 you will only get the "other" collider when unity calls you a OnTriggerXXXX callback.

I was asking if there is any way to get both using a compound object.

Hope everything is clearer now.

Cheers

edited title
Source Link
Notbad
  • 1.1k
  • 2
  • 19
  • 31

Get own Getting child that collided with another objectcollider when collision occurs in a compound object in unity3d?

I have a compound object (a. The parent withof the compound object hierarchy has a rigid bodyscript that is listening to the OnTrigerXXX callbacks of the children events fired by their colliders like OnTrigerXXXX).

  When using this type of configuration there's a problem when we want to do something not only with the "other"compound object when a collision occurs, but with our own child/children, that collidedcollides with the "other" object.

Isother objects is there any way to get this information somehowboth colliders? I mean, not only the "other" collider but our childand the collider that belongs to the compound object itself that collided with "other".?

I could do this by removing rigid body from parent and adding it to all childrenP. Events wouldD: All rigid bodies must be delegated from children to a parent to have a centraliced place to execute the code. The problem is that children of compound object will collide among them (with compound objects this does not happen). Againkinematic, so, I could solve this playing a bitcan't use OnCollisionXXXX with the collision matrix but all this seems too much better when using compound objects. The only problem isinfo param that we don't gethas all the information about our colliding childrenI need in the contacts array.

Any idea?

Cheers.

Get own child that collided with another object in a compound object in unity3d?

I have a compound object (a parent with a rigid body listening to children events fired by their colliders like OnTrigerXXXX).

  When using this type of configuration there's a problem when we want to do something not only with the "other" object when a collision occurs, but with our own child/children, that collided with the "other" object.

Is there any way to get this information somehow? I mean, not only the "other" collider but our child collider that collided with "other".

I could do this by removing rigid body from parent and adding it to all children. Events would be delegated from children to a parent to have a centraliced place to execute the code. The problem is that children of compound object will collide among them (with compound objects this does not happen). Again, I could solve this playing a bit with the collision matrix but all this seems too much better when using compound objects. The only problem is that we don't get information about our colliding children.

Any idea?

Cheers.

Getting child collider when collision occurs in compound object in unity3d?

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.

Cheers

Source Link
Notbad
  • 1.1k
  • 2
  • 19
  • 31
Loading