- Home /
Is OnControllerColliderHit bad for performance?
function OnControllerColliderHit (hit : ControllerColliderHit)
{
if ( hit.gameObject.CompareTag("Bullet") )
hit.gameObject.SetActive(false);
}
I'm putting this code into my enemy script to detect when he gets hit by a bullet, but I've noticed it's running constantly as it's picking up floors, walls and other colliders. As I intend this to be a mobile game, is that going to be bad for performance? For example, is it calculating all collision data every time it runs, or is the if statement good enough to ignore those calculations?
I'm pretty sure it is calculating collisions whenever it moves regardless of the if statement, it would only act on the one you interested in. It will still recognize the other collisions.
Answer by darthbator · Jun 04, 2013 at 05:52 PM
I've never really even thought about that. You're going to need to be running code all the time to monitor collisions. IDK how else you would track the collision state.
True… But I guess what I'm curious of is whether this collision information is being gathered each frame by the CharacterController anyway, or only if the code contains OnControllerColliderHit
… That would be very useful to know.