How should I optimize the use of 1000s of AIs?

Right now, I’m working on a game that I think is a bit too ambitious but I’m giving it a try, hopefully it doesn’t become too much to process.

But think of it like a total war game (in combat mod) but units are scattered across a much larger map. Each tribe has its own units (let’s say 30-50 men), and there’s probably around 100 tribes. I already set up the map and the settlements etc…

But for AI, There could be possibly 3000-5000 men on the map controlled by AI (not all are visible to the player).

Do you think this is possible performance wise? The units are really small (like total war units). They won’t be all fighting at the same time, only the ones at war with each other will have moving units, the others will be just static standing still.

How should I go about it, or should I abandon this idea?

Thank you in advance.

Well, there is no easy answer for this. If you have good understanding of C++ you could make a manager that decides which units should move and when to make them sleep (you could do it on Blueprints too, but for such amount of AIs execution via C++ will make a huge performance difference). I’m currently working on a plugin for the marketplace that could be useful for you (its a multi thread solution that manages all of the AI decisions in a second thread unless its actually rendered), sadly I do not have an ETA for the plugin but you could try a similar aproach. The basic principles are:

. Keep a list of the areas of the map that are actually being displayed.
. Sleep all units outside said areas (make them to stop ticking, make them hidden in game, pause any component, remove collisions).
. Awake all units inside said areas (revert previous process).

Since you do not need the ai to do anything while they are not visible you can leave out the multi thread part since they will be just still.

Hope this helps you to at least get some grasp on how to do it. Sadly i cannot share any of my code since I intend to sell it at some point. Good luck with your project! sounds promising!

Thank you! Well, what I meant is that the AI units will be sleeping until at war. So I can imagine your multi-thread solution could work for that too.

I look forward to seeing it on the marketplace when it becomes available.

Unfortunately this is what separates the Professionals from the amateurs. Best Advice I can give you, is figure it out. But the bottom line is Garbage collectors are not a scalable technology. unreal was never intended to have that much going on. If this is a multiplayer app, then you are also wanting to send those 1000’s of changes to each client. Since the bandwidth limit as around 50kb / second that gives you around 50 bytes per ai per second. divide that by 30, and you get 1.6 bytes per frame. Making it impossible. So you have to reduce the amount of information, hack in some way to update 1000’s of npc’s, that is not an unreal way. And that means you will likely not find a solution. Nobody who has done this is just going to open their depot and let you have the magic that makes their stuff work. Good Luck…