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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

CPU bound when animating 500 units?

Discussion in 'Animation' started by eXonius, Oct 17, 2016.

  1. eXonius

    eXonius

    Joined:
    Feb 2, 2016
    Posts:
    207
    I'm making an RTS and out of curiosity I just made a simple performance test by placing 500 units, each being just a simple GameObject with a Skinned mesh Renderer and an Animator attached that loops through some animations (using the free asset "Toon RTS Demo - Knight").

    The unit model seems simple enough and while I understand there is some overhead involved in rendering 500 units in view at the same time I don't really understand why it should make me CPU bound to below 40 FPS? Is animation really so CPU heavy? I can see in the profiler that most of the time is used by Animator.Update.

    If simply animating the units on screen is going to eat all CPU power then it's going to be a real problem doing pathfinding and obstacle aviodance which is what I expected to be the CPU intensive part, not animating the characters, I thought that was more GPU heavy than CPU heavy? Am I wrong in this? Is that not generally the case?

    Is there anything I can do to get better CPU performance for a large amount of animated units? The animations are already imported as Legacy animation.

    And just to be clear I'm talking about performance on PC (Windows).
     
    Last edited: Oct 17, 2016
  2. FrankBuss

    FrankBuss

    Joined:
    Dec 22, 2014
    Posts:
    55
  3. eXonius

    eXonius

    Joined:
    Feb 2, 2016
    Posts:
    207
    Okay so by looking at the stats window it would seem each unit is about 1350 triangles. Perhaps you're right and that is too much for a game with 500 characters on screen? So with lower polygon units I will require less CPU for animation yes?

    Thanks for your advice.

    500 units.png
     
  4. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
  5. eXonius

    eXonius

    Joined:
    Feb 2, 2016
    Posts:
    207
    I don't really know about the number of bones as I just downloaded this model from the asset store and assumed it was simple enough. Maybe it isn't really though.

    Thanks for the GPU skinning advice, turning it on seems to give me at least 17% higher FPS.
     
  6. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Hi eXonius,

    So first advice, never profile your game in the editor, why? Because the editor has many hook in the engine to update tools like memory allocation or updating inspector when values change, etc ...
    Try to profile your game in the standalone version if possible you will see a huge difference for a big scene like that.

    Brainswitch is right, for a rig of this type I would expect at most 20 transform in your rig, if you have more transform than this, you should try to reduce it.

    For a RTS game type, make sure your rig for your unit is set a Generic and not Humanoid, the Humanoid rig does more thing like retargeting, IK, twist bone solve, etc.. which is more cpu heavy and probably not necessary in your case.
    Simply ask yourself:
    does all unit share exactly the same rig and the same animation clip? if Yes, then you don't need retargeting.
    Do I need to use IK for my units? If No and you answered yes at the first question you don't need to use a humanoid rig.

    Also you should use an Optimized Game Object
    https://docs.unity3d.com/Manual/FBXImporter-Rig.html
    In most case you don't need to access the transform hierarchy for your units so simply remove it.

    Also I don't know if it does apply to your asset but if you do have multiple skin mesh renderer on your unit you should try to combine them to reduce the number of drawcall.

    Take a look at this url, which sum up all the tips and trick and gave to you.
    https://docs.unity3d.com/Manual/MecanimPeformanceandOptimization.html
     
    SomeGuy22 and theANMATOR2b like this.