Unity Proximity Warning System Trigger issues

I'm trying to set up a proximity warning system but I'm having some trouble.

To simplify things as much as possible:

I have two game objects in a scene (Object1 and Object2). Object1 has a large child object (twice as large as Object1 or Object2) which has no mesh renderer, but has a box collider (with the Is Trigger box ticked). Object 2 has a rigidbody component.

When Object1 gets close enough that it's child's Box Collider overlaps with Object2's rigidbody, a script on Object1 should Debug.Log the name of the object it's close to once a frame until Object1 moves away.

My code is as follows:

public Collider objectCollidedWith;

void OnTriggerStay(Collider other)
{
objectCollidedWith = other.transform.GetComponent<Collider>();
}

void Update()
{
Debug.Log(objectCollidedWith);
}


Unfortunately, something about my setup isn't working. The console just shows "null" once a frame and the objects getting close doesn't change this.

Can you tell me what I'm doing wrong?

• Can you edit your question to show us your setup of the two bodies, and how you're moving them? As an aside, other.transform.GetComponent<Collider>(); this is a very strange way to just write other; – DMGregory Mar 18 '19 at 18:37