Search Unity

Detecting a collision exit when objects collider is disabled.

Discussion in 'Physics' started by Gun_Asylem, Aug 30, 2015.

  1. Gun_Asylem

    Gun_Asylem

    Joined:
    Dec 28, 2013
    Posts:
    19
    i have a gameobject that acts as a Scale. When you drop an object on it, the onCollosionEnter fires and adds its weight to the Total.

    however, the way i have it set up is, when you pickup and are carrying an object its collider is disabled to prevent it from interfering with other objects.

    so the onCollisionExit can't see the object being picked up because its collider is being disabled before hand.

    is there a way to detect when the object stops colliding with the scale when its collider is disabled?
     
  2. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    I dont think you can.

    Maybe you can instead of using oncollisionenter and oncollisionexit, just use oncollisionstay and grab all your collider info from there. This way when the collider is disabled, oncollisionstay will no longer have it.

    It might be less performant, but its the only simple way I can think of doing it if you only want to use oncollisionxxx (I guess you can maybe start messing with collision layers, but I wouldnt bother)
     
  3. Gun_Asylem

    Gun_Asylem

    Joined:
    Dec 28, 2013
    Posts:
    19
    after some research and trial and error i decided to take a different approach, instead of disabling the colliders i turn them into triggers, this way they dont collide with objects while holding them and scale still detects them when you've picked them up.
     
  4. lmrcarneiro

    lmrcarneiro

    Joined:
    Nov 30, 2017
    Posts:
    1
    I know this is an old thread but @CaliberC could you reply with the solution that you found? I'm having the same problem..