# How to handle large amounts of actors and AI?

**URL:** <https://forums.unrealengine.com/t/how-to-handle-large-amounts-of-actors-and-ai/535318>\
**Category:** Blueprint\
**Tags:** unreal-engine, UE5-0, Blueprint, question\
**Created:** [April 21, 2022, 5:20am UTC](https://forums.unrealengine.com/t/how-to-handle-large-amounts-of-actors-and-ai/535318 "2022-04-21T05:20:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Castineiras](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Castineiras](https://forums.unrealengine.com/u/Castineiras)\
**Post date:** [April 21, 2022, 5:20am UTC](https://forums.unrealengine.com/t/how-to-handle-large-amounts-of-actors-and-ai/535318/1 "2022-04-21T05:20:20Z")

</div>

Currently making a twin stick shooter and I’m noticing I’m getting a lot of lag when the player starts firing a lot of projectiles rapidly or when a lot of enemies are spawned in (roughly 300 simple ai, they only move directly to the player on a small plane). I’m just wondering what I can do to get around this issue. Thanks.

---

<div class="post-metadata">

**Author:** ![TrofimovYuri](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/trofimovyuri/32/467136_2.png) [@TrofimovYuri](https://forums.unrealengine.com/u/TrofimovYuri)\
**Post date:** [April 21, 2022, 7:13am UTC](https://forums.unrealengine.com/t/how-to-handle-large-amounts-of-actors-and-ai/535318/2 "2022-04-21T07:13:12Z")

</div>

Hi! I think in case of large number of projectiles you can use “Object Pooling”. The idea is to reuse objects but not destroy them. I found the plugin on the marketplace wich, i think, can help you with that (i am not test it. It just an option):

> **[Object Pool Manager Plugin in Code Plugins - UE Marketplace](https://www.unrealengine.com/marketplace/en-US/product/object-pool-manager-plugin)**
>
> The object pool pattern is a software creational design pattern that uses a set of initialized objects kept ready to use – a "pool" – rather than allocating and destroying them on demand.

In case of AI, i think, sometimes you don’t need AI at all. It can be simple actors without any “brains” and sophisticated logic. Like projectiles.)))

---

<div class="post-metadata">

**Author:** ![Castineiras](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Castineiras](https://forums.unrealengine.com/u/Castineiras)\
**Post date:** [April 24, 2022, 1:48pm UTC](https://forums.unrealengine.com/t/how-to-handle-large-amounts-of-actors-and-ai/535318/3 "2022-04-24T13:48:18Z")

</div>

Thank you, the object pooling solution seems to be the sort of thing I’m looking for.

As for the AI, I’ve tried to do them in various ways using characters pawns or actors and all of them seem to cause the same performance hit just from calling simple move to actor on a regular basis. Do you have any idea how I could get around this as I’m not sure how much more simple I could make the enemies haha

---

<div class="post-metadata">

**Author:** ![TrofimovYuri](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/trofimovyuri/32/467136_2.png) [@TrofimovYuri](https://forums.unrealengine.com/u/TrofimovYuri)\
**Post date:** [April 24, 2022, 4:11pm UTC](https://forums.unrealengine.com/t/how-to-handle-large-amounts-of-actors-and-ai/535318/4 "2022-04-24T16:11:10Z")

</div>

I think, before any optimizations, you need to find the exact cause of the lags. Is it rendering or AI pathfinding/logic. I found this thread, wich can be helpful:

> [@How can I make AI have less impact on performance?](https://forums.unrealengine.com/t/how-can-i-make-ai-have-less-impact-on-performance/318905/12):
>
> “that big” is relative to the machine its running on. It hasn’t improved really that much, I have done some extend testing on it in recent versions. 400 AI’s Without AI: 11MS Without Movement: 14.5MS PawnMovement: 18MS (acceptable performance, but the quality is not suitable) CharacterMovement: 28MS (Bad performance…) CharacterNavmeshwalking: 27MS (literally just as bad) In conclusion I’m still looking for a suitable AI\_Movement Solution. I hoped the MOBA AI Twitch stream would give some…

To find the exact reason i recommend you to start from simplest solution. Like actor, without navigation, Just “dumb” setactortransform in direction towards player every tick.  
Try use performance profiling tools to identificate the problem.

---

<div class="post-metadata">

**Author:** ![Castineiras](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Castineiras](https://forums.unrealengine.com/u/Castineiras)\
**Post date:** [April 24, 2022, 7:59pm UTC](https://forums.unrealengine.com/t/how-to-handle-large-amounts-of-actors-and-ai/535318/5 "2022-04-24T19:59:44Z")

</div>

So I’ve looked into this a bit more and done some profiling and it seems like the main cause is due to the collisions between enemies.

I’ve got 2 sphere collisions on each enemy, one is the hitbox to damage the player and the other is smaller and allows the enemies to partially overlap but not all the way. If I disable these and just have the enemies move towards the player I go all the way down to 0.7ms frame time but as soon as I enable even 1 of them that jumps up to 10ms or more.

According to the profiler the main cause of the performance hits are mostly on “GeomSweepMultiple” “DispatchBlockingHit” and “MovementComponent ResolvePenetration”. Do you have any idea on how I could improve the performance of these collisions?

---

<div class="post-metadata">

**Author:** ![TrofimovYuri](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/trofimovyuri/32/467136_2.png) [@TrofimovYuri](https://forums.unrealengine.com/u/TrofimovYuri)\
**Post date:** [April 26, 2022, 5:58am UTC](https://forums.unrealengine.com/t/how-to-handle-large-amounts-of-actors-and-ai/535318/6 "2022-04-26T05:58:20Z")

</div>

Any chance you are working on zombie apocalypse game?)))  
Do you use navigation mesh?  
To minimize overhead on navigation (i think this is one of the problems) you can try to “merge” AI actors to clusters. Something like boid flock movement. If AI actors close enough to each other - they begin to share navigation. Because 300 actors at the same screen, i think, will look so messy, so this hack will not be noticable. I think, you can even disable or merge collision in clusters.  
You can also use animation sharing:

> **[Animation Sharing Plugin](https://docs.unrealengine.com/4.27/en-US/AnimatingObjects/SkeletalMeshAnimation/AnimationSharing/)**

I hope this helps you.)
