Check trigger/collider once?


I have two closely related questions, the first which led to the second:

  1. How computationally expensive is it using many triggers and colliders (kinematic only)? I would assume that for OnTriggerEnter to be aware of a collision that behind the scenes it must be checked every frame?

  2. This led me to wonder, is there a way to check (only once, at a precise time) if there are any current collisions for a particular object with a trigger collider? Due to the structure of my game I know exactly when the OnTriggerEnter would be activated, but it is still very useful to use in order to access the objects involved in the collisions.

In a sense, it would be useful to turn on the ‘OnTriggerEnter’ for a short period of time, and the turn it off again afterwards since I know that I will have no relevant collisions. If it would be a form of optimization then I would like to try it.



You can achieve this in a sense by setting the trigger collider’s enable to false when you are not wanting it to report collisions.

The underlying Physics engine (PhysX) can handle a lot of these things very efficiently, though it really depends on your scene. If there are tons of OnTrigger events going off every frame, your issue would be more about all the callbacks happening than anything.

No need to worry about performance really until you notice a performance issue. Just use the profiler to see how things are shaping up as you go.