How To Find Other Collider/GameObject/Transform From Collision/RaycastHit

When I call Rigidbody.SweepTestAll, Rigidbody.SweepTest, OnCollisionEnter , OnCollisionExit, OnTriggerEnter or OnTriggerExit I want to get the Collider or GameObject of the object it is called on. All of these functions return either a RaycastHit, Collision or Collider for one of the objects in the collisions, how can I find the other? Thanks.

The other one as in the current object?

For Collision or Collider, the other object is just Collision.gameObject or Collider.gameObject. The other other object is just the current object (the one that had its collision event called), so just gameObject will give you the reference-- to itself, that is.

void OnCollisionEnter(Collision col)
{
    GameObject obj = gameObject; //Put this script's GameObject into obj
    GameObject otherObj = col.gameObject; //Put the colliding GameObject into otherObj
}

Raycasts don’t have an “other”, they just have a calling object. If the calling object is attached to a gameObject, you can also get that with gameObject, as in this.gameObject.

If this isn’t what you were after, let us know.