Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

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

Discussion in 'Physics' started by aegis123321, Apr 7, 2021.

  1. aegis123321

    aegis123321

    Joined:
    Jul 5, 2015
    Posts:
    35
    It always crash when I try to call Rigidbody2D.Closest2D() and the rigidbody's gameObject is inactive.

    Sample:
    Code (CSharp):
    1. public class CrashScript : MonoBehaviour
    2. {
    3.     public Rigidbody2D body;
    4.  
    5.     // Start is called before the first frame update
    6.     void Start()
    7.     {
    8.         Debug.Log("SetActive(false)");
    9.         body.gameObject.SetActive(false);
    10.         Debug.Log("ClosestPoint()");
    11.         body.ClosestPoint(Vector2.zero);
    12.     }
    13. }
    Unity2019.4.17f1
    I've reported. Case 1327333
     
    Last edited: Apr 7, 2021
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    4,451
    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!
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    4,451
    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.
     
    Last edited: Apr 7, 2021
  4. aegis123321

    aegis123321

    Joined:
    Jul 5, 2015
    Posts:
    35
    Thanks a lot!
    Will it be fixed in 2019.4 LTS? Our project could not upgrade to 2021 for stability.
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    4,451
    That's unliikely to happen given this report. At best 2020.3 LTS.
     
unityunity