Download

Optimization of spawning actors

Hello everyone, I’m new to Unreal Engine.

I’m using a blueprint script to generate and delete around 60 actors in a radius of a flying pawn.
This creates framerate spikes, and I’ve read that this is quite a heavy process.

So obviously I would like to increase the performance of this process by just placing the same logic in C++.
But I would like to know a couple of things first to make sure what I’m doing is right.

1 ) Is the spawnActor function in C++ by itself - faster - than the blueprint node?

2 ) Which kind of properties of the blueprint, increase the processing time of spawning?
I know that for example enabling physics will increase the process time, but are there any more properties that I need to take into consideration?

I thank everyone taking their time reading this, and any kind of help is much appreciated :slight_smile:

I don’t think the C++ function is faster than the BP one, in fact, I think the BP one IS the C++ one. But anyway, both C++ and BP require memory allocation for the actor to spawn. The spawning process itself is slow.

C++ won’t be much faster, Actor Spawning is a heavy operation.

Your best bet is to ‘pool’ the actors you’re spawning. I.e, create them once - and when you don’t need them just switch them ‘off’ / ‘on’ again. I do this for things like machine gun weapons, which might spawn a lot of actors in quick succession - just re-use expired projectiles for new ones.

And this spike happens when you try to create / destroy many actors in the same frame right?
If so, try to not create / destroy everything on a single frame, instead spread it out between many frames.
For example, you could have a fixed number of how many actors you create / destroy per frame, then each frame will spawn / delete actors up to that limit, anything which was missed, can be done on the next frame, and so on.
This might be a solution, but it all depends on what you’re trying to do. :wink: