Skip to main content
Version: Next (dev)

Crowd Rendering and Performance

A Crowd component simulates every agent, but draws only the nearest few thousand per view. This page explains what happens between the simulation and the screen, what each setting costs, and how to find out why a crowd looks or performs wrong.

How agents are animated​

Baked animation​

When the scene starts simulating, the component samples all six clips at 30 frames per second against the skeleton of the first mesh in NearMeshes, and stores every frame as a ready-made skinning matrix per bone. The log reports the result:

Crowd: baked 6 clips, <bones> bones, <size> KB

From then on, an agent's pose costs two table reads per bone and a blend, instead of running an animation graph. The whole table is uploaded to the GPU's skinning buffer every frame, so its size (the clip lengths times the bone count) matters: keep crowd clips short and crowd skeletons lean.

Because every mesh reads the table in the first mesh's bone order, all near and far meshes must have the same bones in the same order. The component checks this and warns if a mesh differs (see Troubleshooting).

Near and far tiers​

Of the agents drawn in a view, the nearest NearCount form the near tier and the rest the far tier:

Near tierFar tier
MeshNearMeshesFarMeshes, or the near mesh if there is none
PoseIts own pose, interpolated between baked frames and cross-faded between clips, written for this agent every frameThe nearest baked frame of the clip it mostly shows, read straight from the shared table. A cross-fade snaps over halfway through.
Pose rateEvery frame, or held at NearPoseRateEvery frame, or held at FarKeyRate

So the cost of a far agent hardly depends on its skeleton, while each near agent writes its whole pose (this frame's and last frame's) every frame.

Presentation​

The drawn characters do not sit exactly on their simulated positions. Each frame, for every agent:

  • Position. The drawn character has its own velocity: the simulated velocity plus a pull towards the simulated position that closes the gap in about 0.35 s. That velocity changes by at most 4 m/s² and is capped a little above the simulated speed, so a push in the simulation becomes a smooth sidestep and agents that are simulated only every few ticks still walk smoothly. A jump of more than 4 m (entering a safe zone, a breach) snaps.
  • Facing. The character turns towards its drawn motion, at most about 4 radians per second. A standing civilian whose group has stopped turns to face the group.
  • Clip. Civilians start walking above 0.45 m/s and stop below 0.25 m/s, start running above 2.2 m/s and drop back to walking below 1.6 m/s. Zombies start running above 1.9 m/s and drop back below 1.5 m/s. Each switch has a different threshold up than down, so an agent near one does not flicker. A switch cross-fades over 0.25 s. Between walk and run the stride phase carries over; other switches start the new clip at a random point per agent, so a crowd does not move in step. The death clip plays once and holds its last frame.
  • Clip speed. Walk and run clips play faster or slower with the drawn speed, relative to the simulation's speeds: walk 1.3 m/s, run 3.6 m/s, zombie walk 1.1 m/s and running zombie 2.6 m/s. Walk clips are scaled between 0.5x and 1.6x, run clips between 0.6x and 1.4x.

Last frame's placement and pose are drawn too, so moving characters have correct motion vectors for temporal anti-aliasing and motion blur.

For feet that match the ground, author the walk and run clips in place (no forward movement of the root) at about the speeds above. The component moves the characters itself.

Which agents are drawn​

Every view selects its own agents each frame. An agent is a candidate when it is alive, or dead and a DeathClip is set; agents inside safe zones and zombies still waiting for their breach are never drawn. Candidates farther than DrawDistance from the camera or outside the view's frustum are dropped, and the nearest MaxVisible of the rest are drawn, nearest first. The test runs over all agents on the worker threads.

All agents draw through the engine's skinned mesh path from one shared skinning allocation, so draws batch per mesh. The component's bounds are always visible; culling happens in this selection, not in the scene's culling.

Shadows​

When simulation starts, the component creates a child object named CrowdShadows, tagged CastShadow, with a Crowd Shadow component. Its bounds enclose the nearest ShadowCount agents of the last main view, plus a small margin, so shadow maps (and virtual shadow maps) refresh only that area. The casters' poses are written once per frame and shared by every shadow view, and each shadow view draws the casters inside its frustum, with the same near and far tiers as the main view.

ShadowCount = 0 turns crowd shadows off. The outline is never drawn into shadows. In the city view there are no crowd shadows.

City view​

When the camera is more than DensityViewHeight above the Crowd component's owner (150 m by default), characters are no longer drawn. Instead the main view shows a density map: one quad per 32 m sector that has anyone in it, 2 m above the ground. Its colour is blue for civilians and red for zombies, mixed by their share; brightness grows with the number of agents and is full at a quarter of an agent per square metre.

Outlines​

Two kinds of outline work with crowds.

Mesh hull. Set OutlineMaterial to a material that uses OutlineHull.plShader. Each agent is drawn a second time with it: the shell is pushed out along the normals and only its back faces show. Skinned characters usually have hard edges and UV seams, where the hull splits open. Enable BakeSmoothOutlineNormals on the animated mesh assets and the OUTLINE_SMOOTH_NORMALS permutation on the material, and the hull extrudes along welded normals instead. The hull doubles the number of crowd draws.

Crowd characters drawn with a mesh hull outline and smooth outline normals baked, about 5,500 drawn; the debug panel on the left shows Outline set to Mesh hull

Screen space. The engine's post-process outline (Rendering.Outline.Enabled and the other Rendering.Outline.* cvars) finds edges in the depth and normal buffers. Its cost does not depend on how many agents are drawn, and with Rendering.Outline.PerspectiveDistance at 0 the line keeps a constant pixel width, so distant characters keep their silhouette. The debug panel switches between the two and starts on screen space.

Performance and budgets​

What each part costs, and the setting that controls it:

WorkRunsScales withSetting
Simulation tickOn one worker task, in the background between two framesAgents, but most are dormantAgentCount
Presentation (position, facing, clip of every agent)Every frame, on the worker threadsAll agents, drawn or notAgentCount
SelectionEvery frame, per view, on the worker threadsAll agentsAgentCount, DrawDistance
Pose writingEvery frame, per viewNear tier onlyNearCount, NearPoseRate
Draw callsEvery frame, per view and shadow viewDrawn agents (twice with a hull outline)MaxVisible, ShadowCount, OutlineMaterial
Skinning uploadEvery framePose table, plus the near tier of each view and of the shadowsClip lengths, bone count, NearCount

The simulation runs at most one tick per frame and drops time instead of catching up after a stall. Below 20 frames per second the crowd therefore moves slower than real time, but the frame rate does not spiral down.

To recover frame time, in this order:

  1. Lower MaxVisible. A few thousand characters fill a street view; more are mostly a few pixels high.
  2. Lower ShadowCount. Distant agents' shadows are rarely visible.
  3. Use FarMeshes with fewer triangles, and a DrawDistance that matches your camera.
  4. Use the screen-space outline instead of OutlineMaterial.
  5. Lower NearCount if the frame is CPU-bound in pose writing.
  6. Lower AgentCount if presentation and selection dominate.

For reference, the screenshot at the top of the Crowds page shows 100,000 agents with 12,821 drawn at about 60 frames per second, GPU-bound, with a 9 ms tick on a background thread.

The profiler shows the crowd's work under these scopes: CrowdTick (the simulation tick), CrowdWaitForTick (the main thread waiting for a tick that is still running), CrowdPresentation, CrowdSelectVisible, CrowdFillSlot and CrowdFillPoses (pose writing), and CrowdEmitAgents (render data).

CrowdBench​

The package source includes CrowdBench, a headless command-line benchmark of the simulation alone. It plays the outbreak scenario as fast as it can and measures every tick:

CrowdBench [-agents 25000,50000,100000] [-runs 3] [-minutes 10] [-seed 1] [-workers N] [-out <dir>]

It prints tick time percentiles, the busiest minute, how many ticks went over the 50 ms budget, the simulation LOD averages and the end state, and writes crowd-bench.json into the output folder. It is built with the package source and is not part of the runtime package.

Debug view​

The Crowd.DebugView cvar (default 0) draws a short vertical line above each drawn agent in the main view:

ValueColours
0Off.
1Character tier: green for the near tier, orange for the far tier.
2Simulation LOD: red for active, yellow for aware, blue for dormant.

Set it in the console (see CVars) or with Agent markers in the debug panel.

Troubleshooting​

ProblemCause and fix
Nothing is drawnThe scene is not simulating: the crowd exists only in Play or Simulate. Otherwise check that NearMeshes has a valid first entry, the meshes have a material (or Material is set), the camera is below DensityViewHeight, and agents are within DrawDistance.
Log: Crowd: the clips could not be baked against '...'. Is it a skinned mesh with a skeleton?The first near mesh is not an animated mesh with a default skeleton, or a clip failed to load. Use an animated mesh asset with DefaultSkeleton set and clips for that skeleton. Nothing is drawn until a clip property changes or the scene is started again; pressing R does not retry the bake.
Log: Crowd: '...' orders its bones differently from '...' and would be posed wrongly.A near or far mesh does not have the first near mesh's bone order. Import all crowd meshes from the same skin.
Characters walk sideways or backwardsThe meshes do not face the engine's forward axis. Set YawOffset.
Limbs are twisted in every clip; arms cross through the body when walkingThe skeleton was imported from a glTF file whose nodes hold a different pose from the skin's bind pose, with an engine before this was fixed. Re-transform the skeleton asset and the clips with the current engine.
Dead agents vanishThere is no DeathClip. Without one, dead agents are not drawn.
Characters stand in the T-pose or rest poseThe clip for that state is not set.
Feet slideThe walk or run clip does not move at about the simulation's speed, or it moves its root forward. Author in-place clips at the speeds listed under Presentation.
Hull outline splits open at seamsEnable BakeSmoothOutlineNormals on the animated mesh assets, transform them, and enable OUTLINE_SMOOTH_NORMALS on the outline material.
Dark blocky shadow acne on the charactersRaise Rendering.Shadows.VSMDepthBiasTexels and Rendering.Shadows.VSMNormalBiasTexels (the debug panel uses 6 and 4).
The crowd moves in slow motionThe frame rate is below 20, so the simulation drops time. Lower the budgets above.
Some agents miss for one frame after raising NearCount or opening another viewThe skinning allocation grows on the next frame; those agents draw from then on.
B or R does something unexpected in a gameThe Crowd component reads these keys directly while simulating.

See Also​