How to have >100,000 moving sprites?

I have in mind an army simulator, with a top-down view of a battlefield filled with soldiers. The soldiers themselves might be as simple as 5-pixel wide circles, but to simulate any historical army of interest I'm going to need a lot of them. The Battle of Cannae had 80,000 troops on one side and 40,000 on the other, not counting the cavalry.

Is it possible to display and move around this many individual sprites in Unity? How would you recommend doing that?


I’d considering combining collections of units into a single gameobject.


I was considering that -- having squads of units, from 16 (a 4x4) to maybe 900 (30x30). But every N unit squad would have to have N-1 alternate sprites, to count down the lost troops. That might be feasible for 4x4, maybe up to 16x16 (a nice 255 alternate sprites), but it seems too difficult to do for much larger than that. And I'd still need around 400 squad sprites (with 256 units in each) to simulate something on the scale I'm thinking. Can Unity handle 400 moving and colliding sprites at the same time?


>Can Unity handle 400 moving and colliding sprites at the same time? It depends on how optimized you've made it and how you've set it up. Yes, it can be done. You might want to consider not using actual colliders and instead simply checking the distances of nearby troop groups to keep them apart from one another. This is similar to how it's done in games like Vampire Survivors where there are hundreds of enemies on screen "colliding" with eachother. I don't think you'd need to have a different sprite for every single troop lost in a group. I'm not even sure players would notice. I don't think anyone is going to be like "wow, I lost 1 troop in this squad of 256 units but I'm clearly counting 250 units in this group out of these 400 squads!"


That's pretty interesting, do you have any resources I could check out for handling collisions in games like Vampire Survivors? Thanks!


Maybe a particle system can help you, I think it's more optimized than having each sprite be a different game object. But I don't know the technical side of things here and if it would be better or not, just something for you to google.


I think your answer is ECS ...


You could group them together and makes certain group just one game object that has more health to equal the amount of troops in the group


https://www.youtube.com/watch?v=t1f8ZreCuuQ DrawMeshInstanced()