Crashes in Rigidbody2D.Closest2D(Vector2) with inactive gameObject(rigidbody2D).

It always crash when I try to call Rigidbody2D.Closest2D() and the rigidbody’s gameObject is inactive.

Sample:

public class CrashScript : MonoBehaviour
{
    public Rigidbody2D body;

    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("SetActive(false)");
        body.gameObject.SetActive(false);
        Debug.Log("ClosestPoint()");
        body.ClosestPoint(Vector2.zero);
    }
}

Unity2019.4.17f1
I’ve reported. Case 1327333

Wow, it’s been a long time since we’ve had an actual crash in 2D physics. I’ll take a look at the case right now.

Thanks for the report!

Yep, it’s simply not checking to see if the underlying Box2D body in the Rigidbody2D is NULL or not. That’s been like that for years.

Fixed. You can track it here.

Thanks a lot!
Will it be fixed in 2019.4 LTS? Our project could not upgrade to 2021 for stability.

That’s unliikely to happen given this report. At best 2020.3 LTS.