May 13 2022

Yes, You Can Animate Thousands of Characters in Real-Time


In this post, you will discover the performance challenges of crowd rendering. Better yet, you’ll learn how to render thousands of character in Unity within your (super tight) performance budget. Yeah, we like it tight around here ;-D

Why Would You Need 100+ Characters in Your Game?

I have no idea about the project you’re working on at the moment. But I’m sure you’ll eventually need to render hundreds or even thousands of real-time characters at some point in Unity. And if you skip reading this post now, you’ll regret it when you fullfil my dark prophecy.

Question: have you played sport games? I’m no big fan of those, but some of my consulting clients are.

Guess what? Those sportful games are infected with crowds. That means, your player REALLY wants to see thousands of observers shouting, fighting, throwing beer at you after puking it, and so on. It adds to the atmosphere after all.

And it’s not just sport games!

Also fighting games, social games, everything games. There’s always a potential need to render thousands of characters in most projects. And if you happen to be the developer behind your bosses’ wishes, well, you better learn how to achieve this - fast -.

So how do you render crowds in your Unity project… like in real-time?

If you just instantiated your characters thousand times, you’d see your frame-rate s(t)ink to 0 FPS faster than you’d see your bank account plummet to zero if your boss fired you because you weren’t able to fix this.

Here’s why Unity’s way will NOT work for you:

What’s the Challenge With Crowd Rendering?

Simply put, the performance of Unity doesn’t scale as you increase your number of animators AND skinning operations you do. Like at all.

In fact, not many engines do scale well with this amount of computational work.

As a quick reminder of these l33t terms:

  • Skinning is about calculating the position of the vertices of your character based on its skeleton and animation states.
  • The Animator component lets you manipulate your skeleton according to your gameplay rules, animations and such.

To give you a baseline: my consulting clients suffer from a minimum cost of 3 milliseconds per frame with just a couple of characters. Imagine with dozens, hundreds or even thousands of them, heh.

It’s clear Unity’s way won’t cut it. So let me walk you through the solutions I normally go for.

Achieving High-Performing Crowd Rendering in Unity

I’m not going to lie to you: it ain’t easy. Nor sexy. But if you truly want this, you’ll have it.

Here are your main two options:

  • A) DOTS and com.unity.animation package: massively parallelize your animation tasks. Bear in mind you’ll have to do tons of coding yourself if you follow this route, but it is well worth it.
com.unity.animation example
  • B) Skip SkinnedMeshRenderer’s & go for MeshRenderers or spritesheet trickery. Hard but worthy path. For example, you can bake your per-frame vertex data into textures and then just sample it in your vertex shaders. Or you can create an array of meshes at different frames and then swap them over time, to name a few techniques.
Passing vertex data as a texture to avoid skining

Independently of the route you choose, here are some addons that will help you reduce the cost of crowd rendering:

  • Use GPU/Compute skinning. Your GPU is much better suited for skinning than your CPU, so activating GPU skinning is especially a good idea in that case. But in general I like to leave it on.
  • Use LODs to reduce the amount of vertices you skin over the distance.
  • Reduce number of bones affecting your vertices to 2.
  • Use the old-but-good legacy animation system.

Going beyond 4 characters will start degrading your performance significantly. Try the easier things first and see how far you go, though!

If you are serious about rendering hundreds of characters in Unity, check out module 2021.07 when you join www.PerformanceTaskforce.com.

(I won’t lie: you still have to put in the hard work. But knowing the tricks I show you will months of research that I already put in when helping desperated consulting clients)

Good luck!

Ruben Torres Bonet

The Gamedev Guru Logo

Performance Labs SL
Paseo de la Castellana 194, Ground Floor B
28046 Madrid, Spain

This website is not sponsored by or affiliated with Facebook, Unity Technologies, Gamedev.net or Gamasutra.

The content you find here is based on my own opinions. Use this information at your own risk.
Some icons provided by Icons8