Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

characterController.move surprisingly low performance

Discussion in 'Scripting' started by Malarhak, May 9, 2014.

Thread Status:
Not open for further replies.
  1. Malarhak

    Malarhak

    Joined:
    Apr 17, 2011
    Posts:
    21
    Hello,

    I've been profiling my code for my enemies (250 of them, 10 fps) and ended up with the characterController.move being the performance eater (70% of perfs).

    So I've been searching around and found this unityAnswer thread which seems similar to my problems, in which people say it's mostly because of the controller's radius/height. i've tried changing that around and it didn't do any good.

    So basically: I assume the character controller is supposed to be able to move waaay more than 250 objects fluidly, right? What could be the source of that slowyness?
     
  2. Smooth-P

    Smooth-P

    Joined:
    Sep 15, 2012
    Posts:
    214
    One reason why CC.Move() is expensive is that CCs won't move through things, unlike even continuous rigidbodies. And that robustness comes with a performance cost.

    Another is that ControllerColliderHitS are heap objects rather than structs.

    A third is that every CC.Move() call requires a context switch from managed to unmanaged code and back.

    A fourth is that Unity is based on a fairly old version of PhysX, and the internal CC.Move() code may not be terribly fast to begin with.

    How many CC.Moves() should you be able to do per frame? Well, I don't really know, but I do know that using CC.Move()s is more expensive and more reliable than rigidbody physics resolution.
     
    Last edited: May 9, 2014
  3. Malarhak

    Malarhak

    Joined:
    Apr 17, 2011
    Posts:
    21
    Ok so maybe I should use rigidbodies? The thing is I want very precise gameplay and movement, and rigidbodies can't really be controlled very precisely, at least from what I've experienced.

    Or maybe recreating a simple equivalent to the character controller checking collisions under it? Not sure how it would turn out...
     
  4. novashot

    novashot

    Joined:
    Dec 12, 2009
    Posts:
    373
    there are prebuilt rigidbody character controllers to start with / test on the wiki such as this one: RigidbodyFPSWalker
     
  5. Malarhak

    Malarhak

    Joined:
    Apr 17, 2011
    Posts:
    21
    Yes but rigidbodies are very unreliable. They are subject to so much physical effects... I'm affraid it would be near impossible to have really precise gameplay
     
  6. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    If you use a rigidbody, you can set isKinematic to true and completely control it yourself. You can also use the layers system so that only certain colliders can interact with the rigidbody.

    Are all 250 character controllers on screen at once? In Adventures of Pip we disable any character controllers off screen.
     
  7. Malarhak

    Malarhak

    Joined:
    Apr 17, 2011
    Posts:
    21
    Well I probably wouldn't need that much on screen, I'd say 100 at the very biggest maximum, probably less. But what I need from the character controllers is very simple, just moving around in my level and sliding around other objects. So I'm starting to wonder if a custom character controller with a raycast under it and a collider for the body wouldn't do the trick...
     
  8. zgthor

    zgthor

    Joined:
    Feb 28, 2021
    Posts:
    1
    Built in CC is more expensive and less reliable, CC has some pretty glaring flaws which made me steer away from it, here is a tread that goes over it https://forum.unity.com/threads/character-controller-unexpected-step-offset-behaviour.640828/ on the other hand as long as you build the CC to your standards rgbd CC can be more reliable on the long run. Btw i am necroing this post because the information that CC is reliable can be misleading to a lot of games
     
  9. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    839
    Perhaps you should consider some else entirely. If you only need simple movement then why not use something like navmesh agents? When done right you can easily smash that 250 limit with them (i.e. don't recalculate a new path every frame for every agent). And I'm sure there are probably some custom solutions out there these days that use DOT to push even further.
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,417
    There are many hundreds of post about the CC so this isn't a good reason to necro a 9 year old thread.
     
Thread Status:
Not open for further replies.