How do i get the source collider on an OnTriggerEnter?

I have two gameObjects, both with several colliders attached.

On the OnTriggerEnter event, i get the "otherCollider" info, so that i know which of the "target" colliders that have collided.

But how do i get information on which of the "source" colliders that is causing the collision? In other words, is there any way to get a "thisCollider"?

If you have a single collider in your "source" object, then just fetching it with the collider property will do it.

If you have several colliders in your "source" object, I think you can get the colliders through the Collision structure, in the contactPoints.

I do have a solution my self that might work, but I'm not sure if it will make problems in the long run or affect the performace too much.

My solution is to add a rigidbody to all the child objects with a collider atteched to it, and then add the OnTriggerEnter script to every one of these objects.

This way, I can do like this:

void OnTriggerEnter(Collider otherCollider)
{

    print("This collider: " + name);
    print("Other collider: " + otherCollider.name);

}

But as mentioned, I'm bit worried that attaching several child objects with their own rigidbody, will affect performance. Or even worse, result in unexpected behaviour.

May work for your collider if you do not have rigidbody. Dosnt if you have.

That would be the collider that is attached to the same gameObejct as your script :o) , so just access it as "collider":

print("Object "+collider.name+" has hit object "+other.name);

void OnTriggerEnter(Collider other)
{

if(other.CompareTag(“YourCollider”))
{

//do somthing;

}

}