Search Unity

collisionDetectionMode cannot be set to discrete?

Discussion in 'Scripting' started by CarlY, Oct 23, 2014.

  1. CarlY

    CarlY

    Joined:
    Nov 5, 2013
    Posts:
    29
    Hello,

    Maybe it's too early in the morning and I'm not awake yet but isn't this suppose to change the collision detection mode of a rigidbody?

    Code (CSharp):
    1. Debug.Log("BallRigidbody.collisionDetectionMode =" + BallRigidbody.collisionDetectionMode);
    2.         BallRigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;
    3.         Debug.Log("BallRigidbody.collisionDetectionMode =" + BallRigidbody.collisionDetectionMode);
    I'm getting:

    Code (CSharp):
    1. BallRigidbody.collisionDetectionMode =ContinuousDynamic
    as a result and checking the scene, I can see that rigidbody is still set to Continuous Dynamic. I'm using unity 4.5.5
     
  2. CrabSchell

    CrabSchell

    Joined:
    May 27, 2014
    Posts:
    9
    I'm following up since this post was never answered and this is still and issue as of Unity v5.2.3p3 & v5.3.4f1. I reported this in the bug tracker (784529) with a complete reproduction case.

    For anyone who stumbles across this post, the collisionDetectionMode property cannot be changed during runtime if it's initial value in the inspector is not set to "Discrete". Otherwise, the collisionDetectionMode property seems to ignore any value passed to it.
     
  3. xaldin-76

    xaldin-76

    Joined:
    Oct 1, 2016
    Posts:
    25
    Unity 2019.4.19 And this issue still persists.. Setting the initial detection mode to discrete doesn't fix the problem too.
    At runtime, changing the detection from continuous to continuous speculative works, but changing it back to continuous does not really set it, only the enum changes, and the detection stays as continuous speculative forever. There seems to be a fix in the inspector when pausing the game, resetting isKinematic (true>false>true) then choosing a new collision detection, this will work, but I don't want the object to stop moving suddenly while in game. Is there any other way to reset the physics detection for the object?

    Edit: A workaround is resetting isKinematic and reassigning object's velocity

    Vector3 tempVel = myRigidbody.velocity;
    myRigidbody.isKinematic = true;
    myRigidbody.isKinematic = false;
    myRigidbody.velocity = tempVel;
    myRigidbody.collisionDetectionMode = CollisionDetectionMode.Continuous;
     
    Last edited: Feb 8, 2021