Search Unity

Disable collider, How to call OnCollisionExit on other interacting objects?

Discussion in 'Physics' started by CGDever, Feb 22, 2019.

  1. CGDever

    CGDever

    Joined:
    Dec 17, 2014
    Posts:
    156
    Hello!
    There are 2 objects that interact. If one object disables (SetActive(false)) the collider, then the second object will not receive the event OnCollisionExit.

    This is a big problem for me. How can other objects know that the object is disabled?
    I know that I can save objects in OnCollisionEnter and call something like this:
    Code (CSharp):
    1.  
    2. void OnDisable(){
    3. while ( collisions.Count > 0 ) {
    4.         MonoBehaviour[] mb = collisions[0].GetComponents<MonoBehaviour> ();
    5.         for (int i = 0; i < mb.Length; ++i)
    6.             mb[i].OnCollisionExit (collisions[0]); //<<< private
    7.         collisions.RemoveAt ( 0 );
    8. }
    9.  
    But such as OnCollisionExit is private my perfect plan fails XD.
    There is another way to write wrappers. But it is extremely inconvenient for the 21st century. Is there some easy way to call all OnCollisionExit() ?