Search Unity

Question OnTriggerEnter fires but OnTriggerExit does not

Discussion in 'Physics' started by antsy1992, Feb 2, 2024.

  1. antsy1992

    antsy1992

    Joined:
    Jan 8, 2021
    Posts:
    8
    Unity_CNJ7zOsM7Q.gif
    “-1324” is green road, “-68908” is white road

    cRvAq0X4Y0.png
    This script is on both green road and white road


    The green is generated road with mesh, collider, rigid body. When I move my cursor on the GIF one end of the road collides with another road (white) and OnTriggerEnter fires on both roads script, which is fine. However when green road leaves collider of white road theres is no OnTriggerExit on both of them! It fires though if I move the whole green road object. Why this happens and what could be a workaround?

    Unity-2022-3-LTS
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,444
    I know that triggers will lose their overlap state (they forget their knowledge of things that are inside them and due for OnTriggerStay/Exit calls) when anything significant changes about those things like a transform changes parents.

    If you're in the middle of generating the green mesh, I am going to take a guess that triggers also lose their overlap state when you modify the mesh that makes up the collider(s).
     
    antsy1992 likes this.
  3. antsy1992

    antsy1992

    Joined:
    Jan 8, 2021
    Posts:
    8
    Yeah I think you are right