1
\$\begingroup\$

Way over 90% of the performance cost seems to be coming from colliders parented to animated bones. If I disable Motion & Animation I can spawn 20 soldiers with around 1ms cost on my mid-low end system. Unfortunately even when the soldiers are "not moving" the idle animation requires the colliders to move with the bones. With motion enabled the performance of 20 soldiers is roughly 15ms. I managed to improve performance by creating a simple hitbox (see left photo), the performance of 20 such soldiers is 10ms. Removing all colliders from the Soldier again lowered performance cost down to 1ms.

The hitbox colliders have been disabled for all collisions in the Physics Manager. Obviously they are not set as static. They are for raycast detection ONLY.

enter image description here

I have developed a 6th sense for when I'm "doing something wrong". Are moving colliders really that expensive?

Inspector Settings:

enter image description here

Physics:

enter image description here

Script attached to Collider:

enter image description here

\$\endgroup\$
  • 2
    \$\begingroup\$ Why would you move them every frame? Keep one big bounding box for the model, something it will always be fully inside of. Only move the hitboxes when theres a bullet in the large bounding box. That's the only time you need to care about its position. \$\endgroup\$ – Peethor May 12 at 11:55
  • 1
    \$\begingroup\$ Can you show us how you've configured these colliders and their containing object, including if they have a Rigidbody, how their physics layer is set up, etc? \$\endgroup\$ – DMGregory May 12 at 12:00
  • \$\begingroup\$ Do you have one or more Rigidbodies in that hierarchy? Where? \$\endgroup\$ – DMGregory May 12 at 12:07
  • \$\begingroup\$ @DMGregory only one at USMarine_M16A1, third from top \$\endgroup\$ – AzulShiva May 12 at 12:10
1
\$\begingroup\$

According to Unity any Collider that will be moved should have a Rigidbody attached to it with isKinematic checked. That solved my problem.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.