# Spawning with c++ causes a ton of lag 

**URL:** <https://forums.unrealengine.com/t/spawning-with-c-causes-a-ton-of-lag/2653714>\
**Category:** C++\
**Tags:** unreal-engine, question, Blueprint, CPP\
**Created:** [September 4, 2025, 5:55pm UTC](https://forums.unrealengine.com/t/spawning-with-c-causes-a-ton-of-lag/2653714 "2025-09-04T17:55:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![OH\_NO\_OH\_NONO](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OH\_NO\_OH\_NONO](https://forums.unrealengine.com/u/OH_NO_OH_NONO)\
**Post date:** [September 4, 2025, 5:55pm UTC](https://forums.unrealengine.com/t/spawning-with-c-causes-a-ton-of-lag/2653714/1 "2025-09-04T17:55:16Z")

</div>

Hi,

I have a game where I spawn in a bunch of actors in specific places (based on a changing database so I can’t put them in manually) on begin play. I have been using some BP scripts to do this but I wanted to switch this code over to c++. When I use c++ to spawn the actors now there is a ton of lag when playing. The spawning code happens at begin play and then is over, so I am totally lost as to what is causing it to drop in quality so dramatically. Any help or ideas is appreciated!

---

<div class="post-metadata">

**Author:** ![nande](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nande/32/1057698_2.png) [@nande](https://forums.unrealengine.com/u/nande)\
**Post date:** [September 5, 2025, 3:39am UTC](https://forums.unrealengine.com/t/spawning-with-c-causes-a-ton-of-lag/2653714/2 "2025-09-05T03:39:17Z")

</div>

> [@Infinite loop error](https://forums.unrealengine.com/t/infinite-loop-error/2653552/4):
>
> grab that list of actors to spawn and save in a variable in the class. (toSpawn) have a variable for how many actors to spawn per frame. have a function that spawns actors (SpawnActors) inside you loop the toSpawn array, from the last point until last+howManyPerFrame. you spawn. update last. set a timer for next frame to the same SpawnActors functions. if last \>= total then return without setting a timer.

---

<div class="post-metadata">

**Author:** ![OH\_NO\_OH\_NONO](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OH\_NO\_OH\_NONO](https://forums.unrealengine.com/u/OH_NO_OH_NONO)\
**Post date:** [September 8, 2025, 4:53pm UTC](https://forums.unrealengine.com/t/spawning-with-c-causes-a-ton-of-lag/2653714/3 "2025-09-08T16:53:43Z")

</div>

Thanks for replying, I tried that and it still isn’t working. Even if I spawn only 10 actors each second it is still incredibly slow during play. Is there anything different between c++ spawning and blueprint spawning that could cause the issue?

---

<div class="post-metadata">

**Author:** ![nande](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nande/32/1057698_2.png) [@nande](https://forums.unrealengine.com/u/nande)\
**Post date:** [September 8, 2025, 10:56pm UTC](https://forums.unrealengine.com/t/spawning-with-c-causes-a-ton-of-lag/2653714/4 "2025-09-08T22:56:11Z")

</div>

> [@OH\_NO\_OH\_NONO](#):
>
> Is there anything different between c++ spawning and blueprint spawning that could cause the issue?

even though i’d want to say cpp is faster, the overhead is minimal afaik.

it might well be an issue with loading the assets, and their size on disk and having to set them up on the gpu.

try spawning empty actors and see if you notice any difference.

otherwise you might try spawning things on different threads but i don’t recall atm how to do it safely. feel free to google around.

another possible optimization is find a way to load things that are relevant first. e.g. if you’re using world partition there’s something that can help you by setting the loading grid properly.

if you don’t use world partition you can create your own solution. in my game for example, i only load the areas during chapter transitions, and only loads the area you’ll be playing in.

if you use pcg you have the same grid for generation and newer versions have the “hierarchical generation.”

there are also LODS that might help. and mipmaps. and virtual texture. all those things could impact loading. how to know? you need to read the docs and run the profiler, maybe the “statistics” panel. there are great videos from epic in youtube about hitches and loads.

make sure your lods are properly set, that your meshes are not bloated (even with nanite there is a discard % or by error, in nanite AND the fallback mesh (separately)).

also think about using object pools i’ve made a generic one. it could help. as you can force spawn them at the start of the game, but keep them hidden until you actually need them. you have to keep an eye on memory, i wouldn’t recommend “preloading” much. but i do recommend pooling. [Making sure you're not a bot!](https://codeberg.org/jerobarraco/JUtils/src/branch/master/Source/JUtils/Actors/Pool.h)

if the engine takes times loading/spawning an asset, it does not matter (much) _how_ you do it, it will still take long time to load.

so you’ll have to focus an what are you loading, maybe why are you loading it.
