OnCollisionStay not calling consistently

I have always assumed that OnCollisionStay would fire always in conjunction with OnCollisionEnter.
However, it doesn’t appear to be the case.

Here, depending on the bounce combine method on the Sphere’s physics material. OnCollisionEnter will fire if it’s set to Minimum. When Maximum, the event doesn’t fire.

8124158--1053284--Unity_qiua35qCLV.gif

Using Unity 2021.3.0

Script added to Sphere:

public class CollisionEvents : MonoBehaviour {

    private int fixedFrames;

    private void FixedUpdate() {

        fixedFrames++;

        if (Input.GetMouseButton(0) && Time.frameCount > 100) {

            GetComponent<Rigidbody>().AddForce(Vector3.up * Random.Range(1f, 2f), ForceMode.Impulse);
        }
    }

    private void OnCollisionEnter(Collision collision) {

        GetComponent<Rigidbody>().velocity = new Vector3(collision.relativeVelocity.x, collision.relativeVelocity.y);

        Debug.Log("<color=red>Collision ENTER " + fixedFrames + "</color>");
    }

    private void OnCollisionStay(Collision collision) {

        Debug.Log("<color=green>Collision STAY " + fixedFrames + "</color>");
    }

    private void OnCollisionExit(Collision collision) {

        Debug.Log("<color=yellow>Collision EXIT " + fixedFrames + "</color>");
    }
}

Sphere setup:
8124158--1053287--sphere.png

Is this a Bug? Shouldn’t OnCollisionStay always fire immediately after OnCollisionEnter?

No.

OnCollisionStay is the same as OnCollisionEnter, just that you get Enter only once when there’s an initial contact. In the next simulation step, if it continues to be in contact, you’ll get an OnCollisionStay.

This is the same for both 2D and 3D.

1 Like

Ok, thanks for the clarification.