Any suggestions on how to improve performance of 1000 simple AI moving?

Hi!

So I was thinking about making some RTS Game that has alot of pawns moving around. 1000 pawns max.

So far I managed to make 1000 pawns move at the same time and play some animations at lowest 30 fps. Which is good, since my laptop is not so op and 30fps in RTS game is playable.

Whenever the pawns are standing still, or not all of them are moving I can get even 100+ fps. Whenever all pawns move, but do not collide with each other I can get 60+ fps. Whenever they start to collide with each other then fps drops to 30 or abit lower (lowest was 27, when recording even lower).
So the problem lies mainly in collision between pawns. But I do not really know what to do about that.

I played a RTS Game 8Bit Armies where pawns do not collide, they are just pushed away from each other. So if I could implement this kind of thing would it be better for performance?

If you have any suggestions, please let me know!


(When not recording my fps is waaay better.)

1 Like

You are right. I cannot do that with normal ue4 movement system and collisions. I have to make my own system.

And I did it. I can move 1000 pawns with 60 fps no drops, while recording 30-40fps.

I made my own grid system, where pawns move. With this grid system I can make the entire game with no collisions at all. Pawns do not rely on collisions.
Grid is a map of keys (locations) and values (data structure). Data is for example enum (Free Grid Cell, Obstacle…). Whenever pawns move they get all cells around them (8) and loop through them. If the cell is free then they can move there, otherwise find new cell or cancel move.

I just made the system and it needs alot more improvements. But essetially it works, and I can move now a bunch of pawns around. Btw I did it all in BPs with nativization.

I tried it out with 3000 pawns, but it is too much. Even if they are not moving i get -30fps.

1 Like

So i did further upgrading and decided to switch to CPP because of performace. BPs just cant handle for loops. Even if I loop every few 0,1 seconds 10k times. For CPP its nothing, but for BPs its painus in the. So now I have to rewrite everything in CPP and after maybe I will be able to handle even more then 1000 pawns.

Disabling collision is certainly removing a bottleneck in it, that’s for sure. That’s part of how NavMeshWalking works, it doesn’t check for collisions with world static objects, assuming that the navmesh will have precalculated where any world static objects are.

Problem here, being, you’ve got entirely too many non-static objects. Perhaps using the CrowdMovementComponent might get you some of the benefits, without losing all collision capability.

That said, handling this many things, you’re going to have issues, and you’re going to need to invent some novel things to make something like this work. Things like handling movement, animation, or AI either off-thread or on a staggered basis, or both. You’ll need to make sure that your AnimTrees are highly optimized, that your AIs are highly optimized, and that you can live with whatever tradeoffs have to be made to actually handle having that many whatevers in the world at once.