Best way to spawn actors dynamically.

Which is the best way to spawn actor dynamically and in a performance effective way.

I have read using multi-threading to spawn actors is better compared to just spawning them manually.

I am currently spawning a Blueprint in this manner.

.h


	UPROPERTY()
	ABallBall* Ball;

Here SpawnObjectClass is a blueprintclass

.cpp
if (bSpawnObjects == true)
{
for (i = 1; i <= 50; i++)
{
FVector LoopSpawnLocation;
FRotator LoopSpawnRotation;


SpawnObject = GetWorld()->SpawnActor<ASpawnerBlock>(SpawnObjectClass, LoopSpawnLocation, LoopSpawnRotation);
FVector Scale;

SpawnObject->SetActorScale3D(Scale);
}
}

How ever I think i would think it will better if i spread the spawning across a few ticks rather than spawning all objects in one tick. Other than that, should I make any changes?
Should I utilize multithreading for this work?

Doing deferred spawning over multiple frames is most certainly enough. You can always profile your project later. No need to over think and over optimize ahead of time.

It’s fairly common advice to leave performance optimisation for later, and only address problems when they arise, but to answer your question,
you will need a class level counter variable that keeps track of how many instances have already been spawned.
You can then also, per tick, keep track of how much time has passed since the tick started (UDK had functions Clock() and UnClock(), not sure what the UE4 equivalents are), and if time passed gets larger than the DeltaTime, you can abort and continue spawning instances in the next tick.

As for multithreading, I have not looked at that yet, so sorry, can’t help you there.

I actually testing to spawn 100 actors per tick. I am going to need about 30 or so which I can spread across a few ticks. But I tried 100 just as a test and it caused a slight bit of lag. But I guess i am not going to use it anyway.

Sorry I didn’t get the Clock and Unclock part. I can do something like that in ticks but it might get a little complicated.