A project I’m working on calls for really dense crowds in a tactical RTS, and I’m debating on what sort of system to use for them. They’ll need to interact with the player’s units (react appropriately to their actions), so I’ll need to access them individually somehow.
We’ve considered script-generated sprites, but I’m wondering if in the end just making really low resource prefabs might be more effective.
Essentially, this kind of a thing uses some clever tricks to keep individual elements in a swarm away from each other, and collidables. You are going to have to develop the Unity-specific implementation yourself, as I couldn’t be bothered to help you with something so complex aside from giving you reading material on the subject.
With Unity, though, I’d strongly advise against prefabs. I’m working on a similar idea at the moment, using 2D sprites and some rather silly techniques to handle 500 or more moving character billboards on the screen at a time… each with a sort of hivemind AI… In my testing, Unity can handle about 100 of these characters moving around pretty well. Once you get into the realm of 250-300… Well, it slows to a crawl. I was able to top my computer out at a thousand if I did some work with swarm AI, and to start grouping tasks and whatnot by proximity, but most of my bottleneck was rendering. Once I started batching up the billboards by location clumps, it really sped up.
It’s tricky, and I really wouldn’t suggest one GameObject per character. I’d really suggest a single class that will do all of the legwork for you for each individual swarm, and use the manual mesh/sprite rendering tools to draw them each frame… It’s going to speed things up tenfold. It might even be faster to manually push the information into the GL interface, but you’re going to need to REALLY know what you are doing with both Unity, and OpenGL voodoo. (Luckily I’m a prior JOGL programmer).
I wish you the best of luck, check out the reference for manual mesh rendering while you are at it.
Thanks! This is exactly what I was looking for, just wanted some opinions on the most practical way to handle the issue. I’m not much looking forward to working with sprites over super low poly models, but I’ll feel better if I know it’s the best option
I appreciate the specific numbers - 100 to 300 to 1000 really helps me visualize what I’ll be dealing with. And that was testing with single plane sprites? And when you say batching the billboards do you mean handling a group of multiple ‘people’ as one? Forgive me for the n00b questions, I’ve never dabbled in this sort of thing before. I’m expecting both the swarm ai and the graphic handling of so many objects to be quite the challenge.
Thanks for the luck, I’ll need it :-p Did you have any specific manual mesh reference in mind? I didn’t know of one within the Unity reference material, and again, never done this - manual mesh or swarms.
Search for DrawMesh. It should be in there somewhere.
Yes, I am actually building an orthographic side-view game sort of using billboard sprites, and none of them actually have their own collision boxes… I’m using something of a custom collision script to handle it all.
Note that my numbers will not be representative of what you can manage through the engine. I’ve got over thirteen years of programming experience, so inevitably, I’ve learned some tricks through the years at getting things to work with minimal processing.
With batching, I’m actually just handling an entire area’s functionality through a single object. All enemies in one area are just bits and bobs of data, and the area itself will manage the majority of the representation of what’s going on. I’m not actually storing any individual characters in a gameobject itself, in order to avoid the overhead.