CharacterController Really high cpu spike

I’m using a character collider on a fly camera to detect collisions. I noticed that when I hit certain objects the cpu would spike in the profiler. It would be higher than the actual rendering time. Is there a specific reason for this? I think it’s actually causing my unity to crash.

I’ve read some other posts related to performance and the character collider but still unclear as to reason why it’s using so much cpu.

I’m guessing that it might be something with the way the object is modeled.

Any help would be appreciated.

Hi, welcome to the forum!

Interesting… do the troublesome objects have anything in common as far as you can tell (they’re mesh colliders, say, while the others are primitive colliders)?

The collider is a sphere collider and the objects that I’m colliding are really high poly and non-convex if that matters. around 28000 tris.

I asked the modelers to do model checks and they said there were no open edges or anything.

Does it have to do with the fact I’m calling charactercontroller’s move function? I tried it both in a fixed and normal update function.

Right now I’m using a rigidbody and moving it with velocity and that seems to work fine. The problem is that at high velocities it penetrates objects unless I use a large collision volume.

A mesh collider does have to be searched to determine the contact point, so a complex mesh could account for the CPU spike. To avoid the rigidbody passing through the mesh, you could try reducing the value of Time.fixedDeltaTime which controls the interval between physics updates. There is also a technique involving a raycast (eg, see this script on the Unify wiki) that stops fast moving objects penetrating colliders. However, I suspect this will probably cause the same CPU spike as the CharacterController.

Yeah I guess my mesh is just too high poly. It’s just the fact that it spikes so much it actually crashes unity.

Anyways I’ll try out your suggestions. Thanks for the help.