Search Unity

OnTriggerEnter / Exit firing inorrectly

Discussion in 'Editor & General Support' started by mattimus, Jul 9, 2012.

  1. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    I'm getting very unreliable results from using OnTriggerEnter() and OnTriggerExit().

    - When I move a collider into a trigger volume, it will sometimes fire off [Enter, Exit, Enter] over the course of about 4 frames, rather than just the single [Enter]. This happens even when the collider is moving in a linear fashion perpendicular to the trigger volume edge, so it's not being caused by the player swerving in and out of the volume.

    - When a collider sits idle inside a trigger volume, I will occasionally get a random [Exit, Enter] pair over about 4 frames that causes flickering on the object the volume is triggering.

    - If I move in and out of trigger volumes fast enough, I can sometimes get the volume to stick in the 'on' position without having a player inside the volume. This comes from Enter being called and the player quickly leaving the volume without the Exit call.


    The objective is to have something similar to a button that turns on/off depending on whether or not a player is standing on it. I want to use OnTriggerEnter and OnTriggerExit instead of OnTriggerStay because I don't want to have to poll every frame to determine if a player is on the button. Is there a more reliable way to accomplish this?