How to make a mesh disappear AND trigger OnCollisionExit

Hey,
In a 3D platformer, I have platforms that suddenly explode / disappear. I achieve this by disabling the mesh collider on a script attached to the platform, something like:

GetComponent<MeshCollider>().enabled = false;

Issue: when I do this while the player is on the platform, it does not trigger OnCollisionExit on the script attached to the player. However this script is responsible for telling if the player is touching the ground or not.

  • Is there a way to make the platform disappear AND still trigger OnCollisionExit?
  • Should I create a custom event that somehow tells the player that a platform disappeared? How to detect if it is still touching ground in this case?
  • Should I deactivate the platform differently?

Thanks for your help!

If it is a convex mesh collider, you could set it to “is Trigger” instead of disabling it, that should work with OnCollisionExit.

Thanks! In my case it is not convex, do you know another way?

A common workaround seems to be to move the object out of sight and disable/destroy it with a delay (a physics update is needed for the movement to be registered, so it can’t be disabled or destroyed in the same frame).

OnTriggerExit/OnCollisionExit and destroyed GameObjects - Unity Engine - Unity Discussions

1 Like