Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

OnTriggerExit triggered when it shouldn't be.

Discussion in 'Editor & General Support' started by Antony-Blackett, Jun 23, 2011.

  1. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,772
    I have a capsule collider inside a box trigger volume. I also have some spheres that fly through the same position as both the capsule and the box trigger. The spheres are filtered to not collide with either the capsule or the box trigger but every so often I get a OnTriggerExit event in a script attached to the box trigger.

    The event says that the capsule has left the trigger box when in fact the capsule has not moved and has not exited the box trigger. The capsule is the only object in the scene that can collide with the box trigger. The event seems to happen most often when there are two spheres on top of the capsule and the trigger box.

    Is this a known issue or should I try reproduce it in a blank scene rather than sending my entire game? If I do send it what's the chance you guys will actually fix it before I ship my game... This is a pretty ugly bug as it means I cannot trust any OnTriggerExit events at all.

    Note that I never get OnTriggerEnter events that I shouldn't. Only OnTriggerExit seems broken.
    I'm on the latest version of Unity.
     
  2. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,772
    I've found a horrible hacky hack of a hack solution to this problem. When I receive the OnTriggerExit event I check the Trigger box with the Physics.Sphere overlap function and use the same radius and position as my player object. When it return true I know the OnTriggerExit event is a bug and I ignore it, otherwise I do things as normal... Seems to be holding up so far. Fingers crossed.
     
  3. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,772
    I've revisited this issue and I found the real problem here. When a rigidbody enters a trigger zone and then falls asleep inside of it sometimes this event is fired. I believe this is a bug as the rigidbody did not leave the trigger zone at all.

    My solution now if to set the rigidbody in questions' sleep variables to 0, preventing it from sleeping and resolving the issue.
     
  4. PrimeAlly

    PrimeAlly

    Joined:
    Jan 2, 2013
    Posts:
    35
    I've just discovered the same bug and workaround. Would be nice if some Unity engineers could take a look at this bug!
     
  5. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Am sure if this bug has been reported the QA team will take a look, and hand over to the developers if they can reproduce it.
     
  6. jvil

    jvil

    Joined:
    Jul 13, 2012
    Posts:
    263
    +1

    Same bug on Unity 3.5.7. This issue totally broke my gameplay.

    My workaround was similar to OverlapSphere, but I prefer using a simple math function to determine if object was inside sphere, which was faster for me than rely on Physics.OverlapSphere.

    This should be enough critical to release a patch for Unity 3.5.7.
     
    Last edited: Oct 14, 2013
  7. FileThirteen

    FileThirteen

    Joined:
    Oct 23, 2012
    Posts:
    40
    From 2023, I can't be sure this is exactly what is happening to me but I think the sleep/awake issue was affecting me as well so this workaround may still be needed even in 2020.3.43f1. The true issue I was facing is that exit/enter would get called when changing to and from kinematic, for my particular issue I just swapped to freezing constraints instead of using isKinematic, but your work around would probably have worked as well for me. Sorry for the necro but I think the info is useful still.