Copying and pasting your AI isn’t very good on performance… having anything over 20 seems to freak out Unity and cause drastic changes in FPS. Games like Totally Accurate Battle Simulator are a display of this; where having more than 20-30 can slow the game way down, depending on your computer.
However, I have seen many games have 100, maybe 300 AI’s per map, no problem, where a wall of zombies come at you, and each one can be killed individually.
Does anyone have any suggestions on how to maximize efficiency for large numbers of AI’s? Would running all of them from on script in an array help?
It totally depends on your code; there’s nothing magical about the number 20 that would cause any issues or have any effect on Unity. Use the profiler to see where any slowdowns are and fix them.
Well, zombies are stupid, They see a target and walk towards it. It is quite different from having an AI which is pretending to be another player. Then there are many decisions to be made.
Hi, if TABS have performance issues with big amount of characters it’s most likely physics bottlenecking it - they don’t use normal animations, it’s more like animated ragdoll, but by physics engine. Good practice with bigger amount of characters is to load balance their main methods execution - that means don’t update all of them every frame, instead only some part every frame, e.g if you have 300AIs you can execute next 50 every frame - you very rarely really need your AI logic to execute more than few times per second.
If you have groups of zombies, you can cut down the AI processing by considering each group as one entities, instead of a set of individual AIs. So, it does matter whether you see 20 or 100 zombies, it would be one AI computation for all.
There’s a great article in the GDC Vault on this topic by a couple of the AI programmers on Assassin’s Creed: Unity detailing on how they got crowds of 10k+:
For the most part, though, the bottleneck with crowds is on the rendering side, rather than AI code. There’s a ton of other options for optimizing crowds. It depends on what your specific needs are.