Optimization Guide

The "Performance Budget"

Enemy Masses allows you to render and simulate thousands of units, far exceeding standard Unity capabilities. However, magic does not exist. Your hardware still has limits (CPU, GPU, and RAM).

Think of performance as a Budget. You can spend this budget on:

  1. Quantity: The number of agents (100 vs 10,000).

  2. Quality: The complexity of each agent (Model detail, Animation method, AI logic).

The Rule: As the complexity of your agent increases, the maximum number of agents you can spawn decreases.


1. Animation Workflow (Critical)

The single biggest factor in Enemy Masses performance is the Animator Workflow you choose in the Setup Wizard or EnemyCrowd asset.

  • Performance: ⭐⭐⭐⭐⭐ (Best)

  • Scale: 5,000 - 10,000+ units (simple meshes/low poly).

  • How it works: Animations are baked into textures and played entirely on the GPU. The CPU does almost no work for animation.

  • Trade-off: No Root Motion. No animation events. Transitions are simplified.

  • Best For: Grunts, Zombies, Swarms, massive armies.

B. Bone Tracker

  • Performance: ⭐⭐⭐ (Medium)

  • Scale: 1,000 - 3,000 units.

  • How it works: Tracks bone positions on the CPU to allow attaching GameObjects (like weapons) to hands dynamically.

  • Trade-off: Higher CPU cost than Compute Animator.

  • Best For: Units that need to swap weapons at runtime.

C. Mecanim Reader

  • Performance: ⭐ (Lowest)

  • Scale: 100 - 500 units.

  • How it works: Uses Unity's standard Animator component.

  • Trade-off: Extremely CPU heavy. Defeats the purpose of "Masses" if used on everyone.

  • Best For: Hero units, Bosses, or very small squads.


2. 3D Model Optimization

Just because you can render 10,000 units doesn't mean you should use a 50k polygon character for them.

Polygon Count & LODs

  • Use LODs (Level of Detail): This is mandatory for high counts.

    • LOD 0 (Close): High detail.

    • LOD 1 (Mid): 50% reduction.

    • LOD 2 (Far): Billboard or extremely low poly.

  • Target Poly Count: For a horde of 5,000, aim for < 1,500 tris per unit at LOD 0, and < 300 tris at LOD 2.

  • Implementation Note: Enemy Masses itself does not provide the LOD system; it leverages GPU Instancer Pro for this functionality. You must set up Unity LODGroup components on your prefabs and configure them according to the GPU Instancer Pro documentation. Please refer to their manual to understand how to properly bake and configure LODs for instancing.

  • Warning: LODs do not automatically guarantee better performance. A wrong setup with thousands of agents can backfire and cause CPU performance hits (due to the cost of calculating LOD switching for so many entities). Ensure your LOD transitions are efficient and necessary.

Skinned Mesh Renderers

  • One Mesh Per Unit: Combine your character's head, body, and armor into a single mesh. Multiple SkinnedMeshRenderers per agent multiplies the draw calls.

  • One Material: Try to use a single material (texture atlas) for the entire unit.

Weapon Attachments (Pro Tip)

  • Bad: Using "Bone Tracker" just to attach a sword to a hand. This forces CPU calculations for thousands of units.

  • Good: Edit the FBX to have the sword part of the mesh. Use "Compute Animator".

  • Advanced: If you need to hide the weapon, use a shader that clips the weapon geometry (Alpha Clip)


3. Visual Effects (VFX)

When 500 enemies die at once, spawning 500 standard Particle Systems will kill your CPU.

  • Use VFX Graph: Unity's Visual Effect Graph is GPU-accelerated and can handle millions of particles. Always prefer VFX Graph over the legacy Particle System for blood, explosions, and magic effects in mass combat.

  • Limit Instances: Even with VFX Graph, use the Global Max VFX setting like in PlayerSkillManager to cap the number of simultaneous effects. You don't need to see every single blood drop when 1,000 zombies explode.


4. AI & Navigation

  • Quality vs. Quantity: High-quality avoidance (agents not clipping into each other) is expensive.

  • Enemy Masses Default: Uses a lightweight avoidance system.

  • Optimization: For massive swarms (Zombies), allow some clipping. It looks natural for a horde to be dense and chaotic.

Custom Logic

  • Avoid MonoBehaviours: Do not attach custom scripts to the Agent Prefab if you plan to spawn 5,000 of them.

  • Use Managers: If you need custom logic, write a Manager that iterates over the data, rather than having 5,000 Update() loops.


5. Built-in Optimization Tools

While the tips above cover what you can do (Models, VFX, Workflow), Enemy Masses also includes built-in tools to help.

One-Click Performance Mode

The EnemyMassesCrowdController includes an Optimize button (or settings in the Inspector) that automatically configures internal GPU Instancer Pro settings for maximum throughput. This handles technical details like:

  • Culling distances.

  • Buffer management.

  • Thread allocation.

Use this feature to ensure the engine side is running as fast as possible, while you focus on optimizing your content (Assets).


Summary Scenarios

Scenario
Setup
Max Count (Est.)

The Zombie Horde

Low Poly, Compute Animator, Simple AI

5,000+

The Medieval Army

Mid Poly, Bone Tracker (Weapons), Formations

1,000 - 3,000

The Elite Squad

High Poly, Mecanim (Complex Anim), Complex AI

200 - 500

Conclusion: Enemy Masses gives you the power to render the "Zombie Horde" scenario. If you try to render the "Elite Squad" scenario with 10,000 units, your frame rate will drop. Choose your budget wisely.

Last updated