Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Collider component detaching? Whhhuuuu!?!?

Discussion in 'Physics' started by jtsmith1287, Feb 13, 2015.

  1. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    Edit:
    TL;DR -- It's definitely a Unity bug.

    So I have a "skill" or "ability" in my game that creates a shield bubble around my player. The player inherits from a destructible object which lets the player take damage. The shield bubble object also inherits from destructible to keep things simple. But the bubble has the invincible boolean toggled (obviously something I created) and it prevents the shield from taking damage. Once the timer runs out the shield object is destroyed, except we noticed that the player can no longer take damage. It took us a while, but we found that the player's collider remains wherever the shield bubble ended. So like, I could be taking damage at (0, 0), but then if I move to (5, 8) I'll stop taking damage, and then if I move back to (0, 0) I'll take damage again. As if my collider component somehow became detached from the player object. It's a component so I don't know how that's possible, but it's happening.

    I know this is kind of unclear, but it's hard to describe what's going one without writing a novel. Feel free to ask for clarification. Two of us have spent a decent amount of time now trying to figure this out with no luck.

    Thanks in advance for any help.
     
    Last edited: Feb 16, 2015
  2. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,006
    It might help if you could post screenshots of your editor, specifically the Hierarchy window as well as the Inspector window for each of your gameobjects.
     
  3. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    I have to be honest, I think it's a Unity bug. I've spent HOURS going over every small detail in the inspector, hierarchy, scene, scripts... I've used breakpoints and debug messages every step of the way. It boils down to this. I have a convex mesh collider that works perfectly until I create a Sphere primitive with a sphere collider and then destroy it. I toggled Convex off during gameplay and started taking collisions again. I toggled it back on and collisions resumed. So literally nothing changed and it started working. So for now I'm going to just toggle it in my code as a HACK fix and we'll get back it to later I suppose.
     
  4. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    Here's the code that "fixes" my problem. Pretty weak.

    Code (CSharp):
    1.  
    2.     public void TearDown() {
    3.  
    4.         Executing = false;
    5.         //HACK to prevent collision from breaking
    6.         GetComponent<MeshCollider>().convex = false;
    7.         Destroy(Shield);
    8.         StartCoroutine(EnableMeshCollider());
    9.     }
    10.  
    11.     //HACK to prevent collision from breaking
    12.     IEnumerator EnableMeshCollider() {
    13.  
    14.         yield return null;
    15.         GetComponent<MeshCollider>().convex = true;
    16.     }
     
  5. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,006
    Might be a good idea to file a bug report.

    William