- Home /
Alternatives to OnCollision methods/messages for many physics objects?
Are there alternatives to OnCollisionEnter/Stay/Exit
events in legacy/non-DOTS Unity (2019.2) physics/PhysX, better supporting a means of observing the physics world holistically?
While Physics > Reuse Collision Callbacks provide some performance gains, when a high number of rigidbodies are active and colliding, the cost involved in subscribing to these message methods is significant, even when the methods contain no additional logic within.
Adding and removing components (such as a MonoBehaviour that subscribes to one or more of these messages) is feasible, but comes with it's own overhead.
@rhysp Out of interest, how many rigidbodies do you have, and presumably you've already run into performance issues? (Side note: Even having many gameObjects can lag, without rigidbodies.) And I reckon your Physics settings collision matrix is already removing collisions which aren't needed to check?
@JPhilipp the active rigidbodies can be at least 40 in a common situation, often many more. I was cautious to detail any specifics, as acceptable load depends on the hardware/device. Rather, the cost of these methods scales proportionally with the physics complexity and so it seems like a viable focus point for optimisations.
Thanks, yes unfortunately the collision matrix is tuned specifically to the few layers that need to interact, and Game Object complexity/hierarchy is as flat and reduced as possible for our game design requirements.