Is there performance difference between OnCollisionEnter and OnTriggerEnter?

发布时间:2026-01-18 23:34

Create a study schedule and stick to it. Allocate time for reading, writing, listening, speaking, and problem-solving exercises every day. #生活技巧# #英语学习#

Calling the methods themselves should not really matter. The physics system figures out there is a rigidbody collision / trigger collision and after that it figures out if the objects in question implement the respective handler methods. Yes, the OnCollision* methods receive a Collision object which contains far more information about the collision event than you have in the OnTrigger* methods, and that object must get constructed, no matter if you actually need all that information or not. But it's all information which is available anyway from detecting the collision, so we are talking about just a hand full of CPU cycles here.

But it's the detection itself which might matter. OnCollisionEnter only triggers for rigidbodies. Managing a rigidbody require far more physics calculations than managing a simple trigger collider. So you might want to reconsider if all the objects which got rigidbodies in your scene actually need them or if a simple trigger would also do the job (or if you at least can make the rigidbody kinematic to absolve the engine from calculating forces you don't actually want anyway). Generally speaking, you can use a trigger when you have an object which doesn't interact physically. For example, if you would create a modern clone of Super Mario Bros, then:

Mario would have a rigidbody, because you want to be able to detect collisions between Mario and triggers and between Mario and other rigidbodies. The Goombas would have rigidbodies, because when Mario jumps on them, he bumps off a little. This can be easily implemented as a physics collision with a bouncy physics material. The data from the Collision object passed to OnCollisionEnter would also be useful for deciding whether Mario collided with the Goomba from above or from the side. The coins would have trigger colliders instead of rigidbodies, because Mario's movement isn't affected when they are collected. Regular blocks would have rigidbodies marked as kinematic, because although they do not move themselves, they do block the movement of other rigidbodies like Goombas or Mario.

网址:Is there performance difference between OnCollisionEnter and OnTriggerEnter? https://c.klqsh.com/news/view/321209

相关内容

What Is The Difference Between Bell MTS And Bell Mobility
OnTriggerEnter works...sometimes
What is the difference between TEST, TEST
What is the difference between each type of membership?
Grammar: The Difference between Effect vs. Affect
What is the difference between using Archive in New Outlook and simply putting things in a folder?
What Is a One
What is the difference between 'it' and 'test' in Jest?
Affect vs. Effect – What’s the Difference?
Ultimate one

随便看看