# Vertexcraft Crowds of animated characters for Unreal Engine 5.6, 5.7 and 5.8: thousands of them, walking, standing, cheering, as instances of one static mesh. The animation is baked into textures and played by the material on the GPU, so an instance costs the CPU nothing until something changes what it plays.  - **The baker is ours.** It does not use the experimental AnimToTexture plugin, and it is checked against the engine's own skinning: the bake by vertices lands within 0.033 cm of it, the bake by bones within 0.005 cm on the engine's mannequin. - **Two ways to bake.** By vertices (every vertex on every frame) or by bones (every bone on every frame, skinned in the material). By bones the textures do not grow with the mesh: the engine's mannequin takes 0.58 MB instead of 10.9 MB, and a modular soldier of 168,878 vertices fits in 6.2 MB. - **Crowds that move.** A movement component walks the instances to a point or along a spline, around walls by a flow field, keeping apart, each on the walk, run or idle that fits its speed at the rate that keeps the feet from sliding. Mass entities can be drawn the same way, with an optional add-on. - **Close up, the real thing.** The instances nearest the camera become skeletal meshes on the same frame of the same clip, and go back when the camera leaves. - **Per instance:** clip, speed, blend between clips, colour, and which parts of a modular character it wears. - **Bones and sockets** baked by name: hang a sword in every hand, ask where an instance's head is. - **Clip events and notifies**: know when a clip that plays once has finished, and when a footstep notify passes. - **Multiplayer:** what the server plays on an instance plays on every client on the same frame, a client that joins later included. Measured on the development PC, with the machine busy with other work, UE 5.8: | | | |---|---| | Bake of the engine's mannequin, 2 clips, by vertices | 0.5 s | | 1,000 instances, cooked Development game, bake by bones | 12.7 ms a frame | | 20,000 instances with the baked LODs | 11 ms a frame (139 ms with LOD 0 only) | | Movement of 500 walking instances, avoidance on | 0.8 ms a frame | | Movement of 5,000 walking instances | 5.4 ms a frame | | Starting another clip on 6,667 instances, with a blend | 1.8 ms | ## Quick start: a crowd in 10 minutes 1. Enable **Vertexcraft** and restart the editor. 2. Right-click a skeletal mesh (or a few animations) in the Content Browser and pick **Bake Vertex Animation**. The **Vertexcraft Bake** window opens with it listed; add its animations, give each clip a name if you like, and press **Bake All**. It makes, next to the mesh: a static mesh, the textures, a material instance per slot and an **Animation Set** (`DA_<mesh>_VAT`). 3. Drop a **Vertexcraft Crowd Actor** in the level and set its **Animation Set**. Pick a **Shape** (grid, circle, stands, along a spline, or painted), a count and the clips. Every number redraws the crowd at once. 4. For variety: **Jitter**, **Yaw Variation**, **Scale Variation**, **Play Rate Variation**, **Colors**, and **Wardrobe** for a modular character. 5. To make them move, pick a **Behavior**: **Walk To** (drag the Destination diamond in the viewport), **Follow Spline** (the actor's own spline), or **Wander** (each one around where it stands). No Blueprint needed. 6. Press Play. With no clips listed, the crowd plays the set's first clip with Idle in its name. For a behavior, the actor's **Movement** component takes the set's Idle, Walk and Run clips by their names, at the ground speeds the bake measured, unless you list your own **Locomotion Clips** on it. From Blueprint, **Start Behavior** sends them off again, and the Movement component's **Move All Instances To**, **Move Instances To** and **Move All Instances Along Spline** give any order you like. ## Baking The **Vertexcraft Bake** window opens from the button on the level editor's toolbar, from **Tools > Vertexcraft Bake**, or from **Bake Vertex Animation** on a skeletal mesh or an animation in the Content Browser. The **Vertexcraft Bake** window (Tools menu, or the Content Browser right-click) bakes many meshes at once. Each mesh has its animations, each animation its clip name, its loop (Auto, Loop, Play Once) and its own sample rate. **Additional Parts** bakes a modular character (head, clothes, armour of the same skeleton) into one mesh and one set. The settings that matter most: - **Method**: **Vertices** for small meshes and the best quality, **Bones** for big meshes, many LODs or many clips. By bones a vertex follows its four heaviest bones; the report says how far the worst vertex ends up from the engine's skinning (0.005 cm on the engine's mannequin, 0.77 cm on a character with vertices weighted to more bones). - **Sample Rate**: 30 is enough for most clips, the material blends between frames. The report says, per clip, how far it would drift at half the rate: an idle usually loses under a millimetre and can be baked at 10. - **Generate LODs**: a crowd needs LODs. A mesh without them gets them generated for the bake; the skeletal mesh is not changed. - **Convert Materials**: each slot's material is copied as `<material>_VAT` with the animation wired in, so the crowd looks like the skeletal mesh. Materials that use Material Attributes are converted too. - **Bone Tracks**: bones or sockets to follow, for attachments and Get Instance Bone Transform. - **Keep Skeletal Source**: needed for the skeletal swap near the camera. The bake writes a report: textures and their size in MB, how far each clip ends from its start (what Auto decides the loop by), and warnings past 64 MB. ### MetaHumans and parts on another skeleton A modular bake takes parts on another skeleton too: they follow the first part's bones of the same names, like a leader pose, and their own bones keep their place under the nearest bone the first part has. That is how a MetaHuman bakes: body first, then clothes and the face. The face follows the head with no facial animation, and its hundreds of face bones take no room in the texture. A MetaHuman with body, hoodie, cargo pants, shoes and face, each piece of clothing on its own skeleton, with walk, run and idle retargeted from the UEFN mannequin, bakes in 34 seconds into 9.6 MB, every material converted, the worst vertex 4.2 cm from the engine's skinning (clothes weigh some vertices on more than the 4 bones a bake by bones keeps). 300 of them draw at 9.6 ms a frame. A second one, made in MetaHuman Creator with baked materials, torso and hands from his split body, cargo pants and running shoes, bakes in 9 seconds into 4.5 MB: two different MetaHumans in the same crowd. Groom hair is not a mesh and is not baked: use hair cards. ### Your own material Add **MF_VXCVertexAnimation** to your material and plug its **World Position Offset**, **Normal** (turn **Tangent Space Normal** off) and multiply **Base Color** by its **Tint**. A normal map goes into the function's **Normal Map** input, so it turns with the animation. Turn **Used with Instanced Static Meshes** on. Set the material as the bake's **Parent Material**, or let the bake convert yours. ## The crowd component  **Vertexcraft Crowd** is an Instanced Static Mesh component that knows the set. From Blueprint or C++: - **Add Animated Instance(s)**, **Play Clip** (with a blend), **Set Instance Play Rate**. - **Get Instance Clip Name / Seconds**, **Is Instance Clip Finished**, and with **Fire Clip Events** on: **On Instance Clip Finished** and **On Instance Notify**. - **Get Instance Bone Transform** and **Attach Instanced Mesh** (one instance of another mesh following a bone of every instance). - **Skeletal Swap Count**: how many instances near the camera become the real skeletal mesh. Every function also exists in **Vertexcraft Crowd Library** for any Instanced Static Mesh component (plain, hierarchical, foliage, what PCG makes): give it the set's mesh, a material that calls the function and ten custom data floats (**Ensure Animation Floats**). ### Colour and wardrobe **Set Instance Color** multiplies an instance's Base Color. **Set Instance Parts** shows only some parts of a modular bake on an instance: one of three heads, a vest or a shirt, a hat or none. On the crowd actor, **Colors** and **Wardrobe** groups do it for every instance from the seed. ## Actions: hits, deaths, ragdolls For an army that reacts, on the crowd component: - **Play Action** plays a clip once over whatever the instance plays, looped or not in the set: a hit, a cheer, an attack. At its end the instance goes back to the clip it played before, or with **Hold Last Frame** stays on its last frame. A crowd movement stops walking it until then. **On Instance Action Finished** fires at the end. - **Kill Instance** plays a death clip once and holds its last frame; no movement walks the instance again. - **Ragdoll Instance** turns the instance into its skeletal mesh in the pose it is in, falling as a ragdoll pushed by an impulse. Needs the set baked with **Keep Skeletal Source** and a physics asset on the mesh. **Clear Ragdolls** removes them. A ragdoll, like a skeletal swap, wears the bake's materials with **SkeletalMesh** on and keeps the instance's colour (baked with Keep Skeletal Source; the colour goes through the mesh's Custom Primitive Data 10 to 12). - **Face Instance Toward** and **Face All Instances Toward**, on the movement component, turn standing instances to a point: a stage, an enemy, the player. ### Targets by neighbourhood The crowd keeps a grid of where its instances stand, made once a frame the first time someone asks, so a battle doesn't loop over every pair: - **Find Nearest Instance**: the nearest to a place, within a distance or at any, skipping the dead, the ones in an action or a list you pass. - **Find Instances In Radius**: every one in a radius, nearest first. For a blast, a shout, an area spell. - **Find Engagements**: who fights whom against another crowd, in one call a round. Each instance standing and free gets the nearest enemy in reach, and no enemy goes to two; the ones with no one in reach get the nearest enemy standing, to walk to. - **Target Grid Cell Size**: about the reach you ask for most (300 cm by default). ### Formation and flank On the movement component: - **Move Instances In Formation**: a group lines up at a point facing a way, in a **Block** (ranks **Columns** wide, about twice as wide as deep when 0) or a **Wedge**. The point is where the middle of the front rank stands. Each instance takes the slot that keeps paths from crossing (the ones ahead go to the front ranks, left goes left), they all march at one speed so the ranks hold, and each turns to the front when it arrives. - **Flank Instances**: splits a group around an enemy, given its middle and about how wide it stands. The middle of the group lines up in front of it, and **Wing Share** of the group, taken from both ends of its line, goes to the enemy's two sides facing in. It returns who went to the middle, the left and the right, so the game can hold the middle until the wings are in. - **Get Angle From Instance Facing**: 0 in front of an instance, 90 at its side, 180 behind. For a bonus to a blow on the flank or in the back, which is the game's call. Formation orders go to the clients like **Move Instances To**, in slot order, so every machine puts each instance in the same slot. The demo has a battle of two armies of 150 (`AVXCDemoBattle`, about 210 lines): Red marches in a block, Blue flanks it and charges once its wings are in, Find Engagements picks who hits whom, and the game decides what a hit does. ## Movement  **Vertexcraft Crowd Movement** walks the instances of the crowd on its actor: - **Move Instance To**, **Move All Instances To** (spread over a disc so they do not fight for the middle), **Move Instances To** (a group to its own place: squads to different spots, each squad sharing one flow field), **Move Instance Along Spline**, **Move All Instances Along Spline** (spread across **Spline Width**), **Stop Instance**, **On Instance Arrived**. - **Avoidance Radius** keeps them apart; the ones standing step aside for the ones walking through. - **Avoid Obstacles** walks around walls and props by a flow field built from collision tests, and the back of a crowd takes another way when the short one is packed (**Congestion Cost**). Up to 8 destinations keep a field each at a time, solved again by turns on a worker thread. - **Follow Ground** keeps the feet on the ground under them, one trace per moving instance per frame. - **Locomotion Clips**: an idle at speed 0, a walk, a run. Each instance plays the one nearest its speed at the rate that keeps the feet from sliding. A clip's speed comes from its root motion at bake time, or is typed in. ## Mass The bridge to Mass is an add-on in `Extras/VertexcraftMass`, kept out of the main plugin so a project without Mass does not load Mass Gameplay (an experimental plugin that brings ZoneGraph, StateTree and Smart Objects with it). To use it, copy the `VertexcraftMass` folder into your project's `Plugins` folder and enable it. Then add the **Vertexcraft Crowd** trait to a Mass Entity Config next to the traits that move the entities. Each entity gets an instance that follows it and plays the locomotion clip of its speed; destroyed entities lose theirs. The speed comes from how far each entity went since the last frame, so any movement works. Turn **Add Transform** on when no other trait gives the entities a transform. **Colors** and **Wardrobe** vary the entities as on the crowd actor, each from its own seed, and **Skeletal Swap Count** turns the nearest into real skeletal meshes. For a crowd that moves with nothing else, add the **Vertexcraft Wander** trait next to it: each entity walks to random points within **Radius** of where it was made, at a speed between **Min Speed** and **Max Speed**, and stops up to **Max Wait Seconds** at each. They keep **Separation Radius** apart, walking or stopped. There is no pathfinding in it: for walls, Mass's own movement traits. ## Niagara  A Niagara mesh renderer plays a bake by vertices or by bones. **Make Niagara Material** (set, clip, play rate) makes the material instance it needs next to the set: the bake's switches, **NiagaraParticles** on, the clip set, and the base material marked for Niagara mesh particles (without that mark the engine draws its default material). Give the renderer the bake's mesh and that instance. Each particle plays the clip set on the material (**Set Niagara Clip On Material**, or its **ParticleClipStart**, **ParticleClipFrames** and **ParticleClipRate** parameters), from its own random point of the loop. For a clip per particle, set the particles' **Dynamic Material Parameter 0** to what **Make Niagara Clip Parameter** gives (start frame, frame count, time offset, play rate): the plugin's own materials read it, and in yours plug a Dynamic Parameter's RGBA into the function's **Particle Clip** input. The particle colour is the tint. **Make Niagara Material With Clips** takes up to 4 clips, and each particle plays one of them, picked by its own random: a mixed crowd from any mesh emitter, with no module to set up. There is no blend between clips on particles. ## Painting a crowd Open the **Vertexcraft Crowd Paint** mode. It paints the crowd actor in **Target**, else the Vertexcraft Crowd Actor selected in the level; with neither, set **New Crowd Set** to an animation set and the first stroke makes a crowd actor where it starts. Drag to paint instances onto the ground, Shift and drag to erase. **Density** sets how full each dab fills the brush at the actor's spacing. Every stroke is one undo. Each stroke can carry its own **Clip** and **Color**, and **Facing** turns the painted instances to the actor's forward, the way the brush moves (a queue, a march) or toward **Look At** (an audience facing a stage). ## Multiplayer Turn **Replicate Clips** on in the crowd component of a replicating actor. Every machine makes the same instances (the crowd actor does from its seed); the server's **Play Clip** and **Set Instance Play Rate** reach the clients on the same frame, and a client that joins later catches up. The movement component sends its orders for every instance and for groups (**Move Instances To** and **Move Instances In Formation**, the newest 8 kept for clients that join later); each machine walks its own copy, so clips and destinations match and paths may differ by a little. ## Measuring on your machine The demo measures itself: start it with `-VXCBench=1000,5000,20000` and it swaps its crowds for a grid of each count in turn, waits 4 seconds, measures the frame over 5, and writes the results to `Saved/VXCBench.txt` (in a packaged game, under `%LOCALAPPDATA%/Vertexcraft`) before it quits. ## Known limits - Morph targets and cloth are not baked: bones only. - Nanite works with bakes by vertices only. A material of your own that plays a bake has to turn the offset from Instance space, not Local: Nanite's Local space on an instanced mesh leaves out the instance's turn. The plugin's function does it. - The skeletal swap plays the animation as it is: a clip with root motion moves the skeletal mesh away from its instance. - Textures are at most 8192 tall. By vertices, a mesh of 3,900 vertices fits 8,192 frames; the bake says what fits when it does not. - Instances added by hand in the editor start their clip when the game begins. ## Support contato@tessaroapps.com