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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

OnTriggerEnter2D and OnTriggerExit2D firing within a minimal amount of frames

Discussion in 'Scripting' started by barinelg, Mar 18, 2015.

  1. barinelg

    barinelg

    Joined:
    Jun 1, 2010
    Posts:
    95
    Hi everyone. Any idea why the two trigger functions OnTriggerEnter2D and OnTriggerExit2D within a couple of frames, even if the two colliders are still intersecting each other. Both objects are moving (adjusted with Time.deltaTime), but OnTriggerExit2D will fire regardless of them still being on top of each other.
     
  2. Deleted User

    Deleted User

    Guest

    Maybe your objects are moving away from each other ever so slightly due to physics?
     
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,998
    Which unity version? (there used to be bug in older versions 4.x, where enter and exit fired multiple times, even though objects were still overlapping)
     
  4. barinelg

    barinelg

    Joined:
    Jun 1, 2010
    Posts:
    95
    4.6.1 is the version. My initial guess is that the Time.deltaTime adjustment was just enough to make the rather pixel-perfect collision to technically no longer be touching, but there were still situations where it would go almost completely through the object going back and forth on entered and exit. I was able to work around it but still odd.