Skip to main content
Version: Next (dev)

Crowds

The plasma.crowd package simulates a very large crowd, by default 100,000 agents, and draws the part of it that the camera can see as animated characters. It does not create a game object per person. The simulation is a set of plain arrays that advances on a fixed 20 Hz tick, and the renderer draws the nearest few thousand agents per view through the engine's skinned mesh path, with poses that come from animation baked when the scene starts.

A crowd of about 12,800 animated characters on a city street seen from above, with the Crowd debug panel on the left and the profiler overlay at the top right; the stats line reads 80,000 civilians, 19,400 zombies and 12,821 drawn

What the package contains​

PartWhat it is
Crowd component (plCrowdComponent)Runs a crowd simulation in the scene and draws it. Everything you set up is on this component.
Crowd Shadow component (plCrowdShadowComponent)Draws the crowd into shadow maps. The Crowd component creates it on a child object; you never add it yourself.
Crowd.DebugView cvarMarks drawn agents by character tier or simulation LOD. See Rendering and performance.

The Crowd component is in the Gameplay > Crowd category of the Add Component menu.

What the simulation does​

The package is built around one scenario: an outbreak in a procedural city. Read this section before you plan a scene with it, because the Crowd component does not let you place your own streets, buildings or spawn points.

  • The city is generated. It is a 2 x 2 km square with 500 building footprints on a 100 m street grid, four safe zones and two open plazas. It is laid out on the XY plane of the Crowd component's owner and centred on it. The buildings exist only as navigation data; with DrawCity on they are drawn as grey debug boxes. You provide the ground yourself.
  • Agents are civilians or zombies. 20 % of the agents start as zombies in hordes, the rest as civilians. 5,000 civilians gather on each of the two plazas. Civilians walk in groups of up to six, flee to the nearest open safe zone when they see a zombie, and can be bitten (infected, later a zombie) or killed. Zombies hunt civilians. Safe zones shoot at zombies that come close and are overrun once enough zombies get inside.
  • The scenario runs by itself. With RunScenario on, zombies break into both plazas 60 seconds after the start, and four squads receive scripted orders (pursue into a breach, guard a route, fall back to a safe zone). Press B to fire the next breach early and R to restart.
  • It is deterministic. The same seed and agent count give the same result on any number of worker threads and from any camera. Nothing in the simulation reads a camera.

Simulation LOD​

Each tick, every agent gets one of three simulation tiers from what happens around it, never from where the camera is:

TierUpdatedWhere
ActiveEvery tick (20 Hz)Within 64 m of a breach, a zombie contact or a squad.
AwareEvery second tickWithin 200 m of such a sector: zombies or fleeing civilians nearby.
DormantEvery fourth tick (5 Hz)Calm districts.

Sectors are 32 m squares. Because quiet agents move in larger steps, the renderer does not draw them at their simulated positions directly: the drawn character chases its simulated position with limited acceleration, so a dormant agent walks smoothly instead of jumping. See How agents are animated.

Quick setup​

You need one or more animated meshes that share one skeleton, and animation clips for that skeleton: idle, walk, run, a zombie walk, a zombie run and a death clip.

  1. Add the plasma.crowd package to the project in Project > Packages > Package Manager... (see Packages).
  2. Create a scene with a large ground plane. The city is 2 km wide, so a 2,000 x 2,000 m plane under the crowd's owner covers it.
  3. Add an empty game object at the centre of the ground and add a Crowd component to it.
  4. Add your character meshes to NearMeshes. If you have cheaper versions of them, add those to FarMeshes in the same order.
  5. Set the six clip properties, IdleClip to DeathClip.
  6. If the characters walk sideways or backwards, set YawOffset (typically 90°, -90° or 180°).
  7. Add a camera object with a Camera component.
  8. Press Play. The crowd exists only while the scene simulates; in the editor viewport without simulation the component draws nothing.

Start with the default AgentCount of 100,000. If the frame rate is too low, lower MaxVisible and ShadowCount first; the performance section explains which property costs what.

Limitations​

  • The city, population and scenario are fixed in code. The component exposes the agent count, the seed and whether the scripted breaches and orders run, but not the layout or the behaviour.
  • The crowd does not collide with or react to the scene's physics, navmesh, characters or player. Agents only avoid each other and the generated building footprints.
  • Only the first sub-mesh of each mesh is drawn, with one material: the component's Material, or the mesh's first material. Merge a character into a single sub-mesh with a single material (an atlas) before you use it in a crowd.
  • The package also contains a C++ API for replicating a crowd between two peers (interest-managed detail around the guest's camera, a density grid for the rest). No component uses it; it is there for code that builds on the simulation.
  • The package supports Windows (win64) only.

In this section​

  • Crowd component: every property with its default, the keys, the stats line and the debug panel.
  • Rendering and performance: how agents are animated and drawn, near and far tiers, shadows, the city view, outlines, budgets, the debug view and troubleshooting.

See Also​

In this section​