Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Disabled collider is enabled but disabled

Discussion in 'Physics' started by Ambrose998800, Jan 10, 2024.

  1. Ambrose998800

    Ambrose998800

    Joined:
    Jun 23, 2015
    Posts:
    74
    Hello and happy new year!
    I have a object that I switch from skinned mesh renderer to "rigid" mesh renderer and vice versa. This works good, but when I set up the mesh components, I add a mesh collider and I am disabling it right after creation. But it is still enabled and messes with other active collider until I enable and disable it again in the inspector. So it is disabled but enabled at the same moment:
    ColliderDisableIssue - 01.png 1. Mesh collider component is disabled, but mesh collider gizmo is visible and collides
    ColliderDisableIssue - 02.png 2. I enable mesh collider component in the inspector, mesh collider gizmo becomes lighter
    ColliderDisableIssue - 03.png 3. I disable mesh collider component again, gizmo disappears and no collisions (what I want)

    How can I disable it right from the beginning? Here is the code for the collider setup that is called at start:
    Code (CSharp):
    1. void SetupMeshComponents()
    2.     {
    3.         DynamicSoftBody.GetComponent<SkinnedMeshRenderer>().BakeMesh(DynamicSoftBody.AddComponent<MeshFilter>().mesh);
    4.  
    5.         DynamicSoftBody.AddComponent<MeshRenderer>().material = DynamicSoftBody.GetComponent<SkinnedMeshRenderer>().material;
    6.  
    7.         DynamicSoftBody.AddComponent<MeshCollider>().sharedMesh = DynamicSoftBody.GetComponent<MeshFilter>().mesh;
    8.  
    9.         DynamicSoftBody.GetComponent<MeshCollider>().enabled = false;
    10.  
    11.         DynamicSoftBody.GetComponent<MeshCollider>().convex = true;
    12.     }