Many calls to CharacterController in profiler

I have a scene with 6 CharacterControllers in it. Everything works fine for the scene by itself. However, if I play a few of the scenes before it (each have their own objects with CharacterColliders) then I get far too many calls to the FixedUpdate() method of the CharacterCollider script.

Examples (From playing a scene to moving onto next one):

Scene 1 (4 CC’s) - Plays fine
Scene 2 (6 CC’s) - Plays fine
Scene 3 (4 CC’s) - Plays fine
Scene 4 (6 CC’s) - Very laggy due to 252 calls to CC method FixedUpdate()

Heres an image illustrating the matter.

As you can see there are over 6000 calls to the Collider.Move method aswell it is prefixed with the word “static”. None of the objects with the CC’s are static so I am not sure what this means.

All of the objects in the right hand pane refer to the Objects which have the CC’s on them. But there are only 6 objects in the scene and it shows alot more results.

Could this be because VSync is off and I am not limiting the FPS? This issue happens in the editor and on android.

Shameful bump

I have no idea, but a couple of things.

  • Can you set deep profile on? It’ll show you better the calls that lead to “Static Collider.Move”.

  • Can you provide the script that is calling “Static Collider.Move”? I understand you might not be calling it, but deep profiling should show one of your scripts calling something in UnityEngine that leads to “Static Collider.Move”.

  • The fact that this only happens on one scene and not the others means that something in that scene is probably causing it. I would start to disable or delete objects until you stop seeing that. If you get to the point where there is nothing in the scene and this is still happening, then it’s likely to come from the scene before or during the load. I consider this a kind of binary search, trying to find out what is killing the performance.

Yeah, nothing super helpful. In my experience, things like this are a pain to figure out.

It’s not just the one scene (should have mentioned that). It is every scene after, and the calls get more and more each time.

Scene 1 (4 CC’s) - Plays fine
Scene 2 (6 CC’s) - Plays fine
Scene 3 (4 CC’s) - Plays fine
Scene 4 (6 CC’s) - Very laggy due to 252 calls to CC method FixedUpdate()
Scene 5 (4 CC’s) - Calls are increased
Scene 6 (4 CC’s) - Calls are increased again

This doesn’t happen on a particular scene, only after a few scenes have been played.

I will enable deep profiling and get back to you with more detail. Thanks

I have enabled deep profiling but this doesn’t seem to show any more information in regards to the static Collider.Move()

Also when this happens, the profiler just stops and refuses to show any more data.

The above happened on level 6, playing through from 1 - 6. When I go back to the level select scene and click a level after that one I get an even worse FPS drop and even more calls. Even the level select scene has poor frame rate.

Here is the code which calls CharacterController.Move()

bool Update () {
    if (isWalking) {
      if ( ! isIdle || (isIdle && spooked)) {
        Walk ();
      }
    }
}

void Walk () {
    Move(waypoints[num]);
}

void Move (Transform target) {

        moveDirection = transform.forward;
        moveDirection *= speed;
        moveDirection.y -= gravity * Time.deltaTime;
        characterController.Move(moveDirection * Time.deltaTime);
        Vector3 newRotation = Quaternion.LookRotation(target.position - transform.position).eulerAngles;
        Vector3 angles = transform.rotation.eulerAngles;
        transform.rotation = Quaternion.Euler(angles.x,
                                               Mathf.SmoothDampAngle(angles.y, newRotation.y, ref velocity, minTime, maxRotSpeed), angles.z);

    }

Is this the CharacterMotor script? It seems like the move command is getting called in it’s FixedUpdate() cycle. Can you post the FixedUpdate() from CharacterMotor?

I think CharacterMotor is a Unity standard asset, which I don’t have in my project and have never used, so I’m wondering about it’s code.

I found a CharacterMotor script here, but it looks different.

Yes the Character Motor is the standard asset. The Move command comes from the CharacterController (another standard asset) which I think is a dll so I cannot view the code.

Weird man. The Profiler shows that it’s getting called from FixedUpdate() and not Update().

I’m just taking a shot in the dark. Do you have a static reference to any of these classes anywhere? Objects may not get completely unloaded if that happens, so maybe there’s some phantom function calls somewhere?

Hoping someone else has a clear idea of what’s going on…

I don’t use static variables in any of my scripts. I appreciate the help, it’s a very weird issue.

CharacterControllers are terrible they are meant for like a single player game where only the player gets it. The better solution is Capsule Collider and Rigidbody. I guarantee your performance will be 100x better. You will obviously need a new controller though. Free ones existing however.

I am thinking of getting rid of the CharacterController, just wanted to try and figure out the issue. After more testing I came across a lot more calls to Collider.Move() (see pic below). Each animal has several box colliders attached to a mesh (leg, foot, neck etc) which is how I know which part of the body registered a collision. Not sure if this has something to do with it but there are alot of calls to Collider.Move() which reference these:

Even if I got rid of the CharacterController there are still multiple calls to the other controller I use on the animals (AnimalController) so I don’t think that would solve the issue.

Do those colliders or a parent of those colliders have rigidbodies?

No, nothing has a rigidbody. I decided to remove all of the character controllers and just use my own movement. I also removed all box colliders and just used a single capsule collider on the parent. Same problem though. Not with the character controller (since they are gone) but with the AnimalController which is attached to each animal. It seems to be called twice for every animal in the first couple of scenes that you play, and then the amount of calls rises dramatically with the more scenes you play ( I haven’t yet found a pattern ).

There is a “sort of” pattern. The many calls only happen on FixedUpdate() methods. Everything in the scene that uses a FixedUpdate() (Animals, player, gun, bullets), they all have far too many calls. This is only FixedUpdate() methods. All of the Update() and other methods are fine. Hopefully that will help someone deduce this problem.

If you don’t have rigidbodies, attach some. If you are moving colliders, those colliders need have rigidbodies or be children of a rigidbody.

If there is no rigidbody, PhysX assumes the collider will never change and can make some short cuts in calculations. Except this gets completely messed up if the no-rigidbody collider actually does move.

I added a RigidBody to the player and all animals. Still the same issue with FixedUpdate() methods being called more than needed.

It is definitely something to do with going from one scene to the next. Scene 1 works fine, then scene 2 has more than needed calls to FixedUpdate(). But when I play scene 2 first (without playing scene 1) everything is normal.

I have even removed everything from scene 2 apart from the player and there are still 4 calls being made to the CharacterMotor.FixedUpdate() method and more calls to the other FixedUpdate() methods in the scene when I go from scene 1 to scene 2 (playing scene 2 by itself is fine). So this weird problem has nothing to do with my code (the player model is a prefab from a package I have used in previous games and had no problem with).