I am facing a very simple problem about Triggers, but I don't see any way to solve it. I just want the OnTriggerExit
function to be called when an object inside the trigger gets disabled.
Here is the way to reproduce the problem in an empty scene :
Create a cube at (0,0,0) with a collider as trigger and the very simple following script :
public class OnTriggerExitTest : MonoBehaviour { private void OnTriggerExit( Collider other ) { Debug.Log( "Exiting : " + other.name ); } private void OnTriggerEnter( Collider other ) { Debug.Log( "Entering : " + other.name ); } }
Create a sphere at (0,0,0) with a Sphere collider and a Rigidbody which does not use Gravity
Move the sphere out of the box,
OnTriggerExit
gets calledMove the sphere back to (0,0,0),
OnTriggerEnter
gets calledDisable the sphere,
OnTriggerExit
is not calledEnable back the sphere,
OnTriggerEnter
is called
Obviously, I want OnTriggerExit
to get called when I disable my sphere. Do you know any solution ?
I am using Unity 5.4.1f
I could use events in the OnDisable
function of my sphere of course, but it's not very clean. I simply do not understand why OnTriggerExit
is not called but OnTriggerEnter
is.