- Home /
Performance for colliders on almost static objects
Good Day. In my game I have a lot of 3D objects added by player that are located not far from each other. This object almost static. They don't really have any physics, but with one exception. If objects intersect each other, I need to pushing them out from each other. Pushing could cause intersection with other objects.
TO do that I added standard capsule collider on each object and use
OnCollisionStay(Collision collision)
to push them out in my own way.
I wonder if collider on each object will not slowdown my program. Does it make sense to disable colliders for all objects that potentially can not intersect and enable it when required ?
GetComponent<Collider>().enabled = true;
Or maybe unity handle situations with static objects to speed-up calculations ?
Answer by mbro514 · Jul 04, 2020 at 05:01 PM
You should never move a static collider or disable it. If doing either of these is necessary, set the GameObject's Rigidbody to Kinematic in the Inspector. This prevents the GameObject from reacting to the forces of physics, but you can still move it around without destroying the frame-rate of your game. You can change between a dynamic and a kinematic Rigidbody in a script like this:
// I'll assume that the rigidbody's name is "rb"
rb.isKinematic = false;
// This makes the rigidbody dynamic. Set it to true to make the rigidbody kinematic.
These pages in the Unity Manual can give you more information on kinematic Rigidbodies:
Your answer
Follow this Question
Related Questions
How to instantiate prefabbed objects via array in c# ? 1 Answer
Collider help (read description) 2 Answers
Player color change on collision -1 Answers
Collision Killing CPU/FPS/Performance - Suggestions?! 0 Answers
Performance: How expensive are Trigger Collisions? How many collision layers should be used? 1 Answer