Unity: Don’t Cache in OnTrigger

Let’s make it short: Don’t use the OnTrigger callbacks in Unity to maintain caches.


When I say caches, I mean any kind of collection that tracks the objects inside the collider. The callbacks are unreliable, and Unity has no intention of fixing the behavior in the near future.


It’s not guaranteed that you will receive an Exit call for each Enter. Additionally, objects can trigger multiple Enters before triggering an Exit. Most of the strange behavior is caused when objects are disabled or enabled inside the collider. Disabling an object will not send an Exit, but enabling it will trigger an additional Enter. Also, fast-moving objects sometimes don’t trigger correctly.