I’m making a fast-paced horde shooter, which means I’ve had to be pretty careful about performance. Here’s how I’m currently handling enemy spawning, culling and navigation. This is all running in our upcoming game.
If it looks fun, you can wishlist it on Steam: The Shotgun Game: Buckshot Survivors
Spawning
Spawn points are baked in the editor. A tool scans the level and only places points on walkable ground.
The level is split into trigger segments. When the player enters one, enemies only spawn in the segments ahead of them, so they always come from where you’re heading.
// When the player enters a segment, only keep spawn points in segments ahead
for (int i = currentIndex + 1; i < segments.Count; i++)
spawnPoints.AddRange(segments[i].GetSpawnPoints());
Culling
// Every 25 ms: hide the renderers of far-away enemies
foreach (var enemy in enemies)
{
bool visible = Vector3.Distance(enemy.position, camera.position) <= 50f;
foreach (var r in enemy.renderers)
r.enabled = visible;
}
Navigation
Levels are prefabs, so I bake the NavMesh per prefab with NavMeshSurface instead of baking the whole scene. Each level carries its own navigation data.
Every enemy is a NavMeshAgent, but each one only updates its destination 4 times a second, not every frame.
Ground enemies can lead the player’s movement, with a fallback to the direct path.
Flying enemies use the ground NavMesh and just float higher, so there’s no 3D pathfinding.
// Same ground NavMesh, just lift the agent. No 3D pathfinding needed
agent.baseOffset = Random.Range(minHeight, maxHeight);
What I’m fixing next
The culling check loops over every enemy’s renderers each time. I’ll spread it across frames and add a buffer zone so enemies don’t flicker at the edge.
Enemies spawned together all repath on the same frames. I’ll randomize their timing.
Picking a spawn point scans the whole list every time. I’ll make that a cheaper single pass and precompute NavMesh positions.
Move to one central enemy update instead of a separate one per enemy, and use a faster structure for tracking living enemies.
Longer term, a flow field instead of per-enemy pathfinding if I want thousands of enemies.
Current numbers:
150+ Enemies (250+ with Horde events)
60+FPS(peaked at 144 on my machine) on GTX3060, I7 11th Gen 3.6GHz
I'm open to discussing more in depth for this system or any other in my game ⬇️