Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Character controller performance issues

Discussion in 'Editor & General Support' started by chronosapien, Jun 28, 2018.

  1. chronosapien

    chronosapien

    Joined:
    Feb 1, 2011
    Posts:
    73
    We're working on a game and using character controllers for our character's movement/collisions. When we have about 100 characters using character controllers in the scene, our performance drops pretty significantly, with calls to CharacterController.Move taking ~70% of CPU time. Right now we're calling Move in Update and applying some basic movement + gravity, as per the docs.

    How many active character controllers is the character controller system designed for? Is there a way we can optimize calls to Move? If not, is there another system anyone can recommend that is more performant, or is having that many characters just not realistic in Unity?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Also 70% of cpu time in fact, tells the forum absolutely nothing at all. Using millisecs would be best.
     
  4. chronosapien

    chronosapien

    Joined:
    Feb 1, 2011
    Posts:
    73
    I saw that thread when searching for an answer before this post, but it doesn't answer any of the questions I asked: a) how many character controllers is the system designed for (at least a order of magnitude would be helpful), b) is there a way to optimize calls to Move, c) is there another system that is more performant (referring to an asset store solution, not a custom built one based on rigidbodies or other).

    I'm not sure I understand this. Percentage of CPU time makes the performance metric universal. If I said CC.Move calls took 3000ms that would be completely based on my hardware and the state of my PC at that time. I would have to give hardware specs for some kind of context, making it much less relevant for anyone else looking at this.



    I did some performance testing to see how I could improve CC.Move calls (using 100 character controllers in the scene) and found out some things that didn't show up when I searched this topic initially. Hopefully this will help someone else in the future:
    • CC.Move performance is affected by the number colliders in the scene, and probably more accurately the number of colliders the character controllers interact with in any given frame. A single box collider was 2-3x faster for CC.Move than our scene with ~1000 static colliders.
    • CC.Move is about 2x faster with primitive colliders than with mesh colliders in our scene.
    • CC.Move is about 1.5x faster with collisions between character controllers disabled.
    • Increasing fixed time step time didn't seem to have any affect on CC.Move performance
    So in short, reducing the number physics interactions with character controllers is the main way I can find to improve performance with CC.Move. Of course there are also other methods like disabling off screen character controllers, but that might not be a solution depending on the type of game you're making. Also, https://assetstore.unity.com/packages/tools/physics/kinematic-character-controller-99131 (Kinematic Character Controller) seems to be the most popular alternative to Unity's CC. I haven't tested it yet, but the store page describes a few different performance optimizations over Unity's CC.
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    a) I doubt the CharacterController component was built to support a specific number of simultaneous instances. The number that operate smoothly would depend on your CPU performance regardless.
    b) Have you benchmarked against SimpleMove?

    Primitive colliders always perform better than mesh colliders, regardless of using a character controller or not.
     
  6. GloriaVictis

    GloriaVictis

    Joined:
    Sep 1, 2016
    Posts:
    133
    Hello OP - any chance you have tested kinematic character controller already or have any other experience on that matter?

    .Move of our players is about 30% of entire server CPU consumed at this moment which is rather huge and we are looking for potential solutions.