[BUG] FinishSpawningActor extremely slow in 4.4 and 4.3.1

Hello,

When spawning an actor with no component it is extremely in 4.4 Preview and 4.3.1 compared to 4.2.1, about a 100 times.
Here is some code:

for (int32 x = 0; x < 80; x++)
 	{
 
 		grid.Add(UBSPGridRow());
 		for (int32 y = 0; y < 80; y++)
 		{
 			FActorSpawnParameters SpawnParams;
 			SpawnParams.Owner = this;
 			SpawnParams.Instigator = Instigator;
 
 			FVector SpawnVector;
 
 			SpawnVector.Y = this->GetActorLocation().Y + x * 96.0f - 96.0f;
 			SpawnVector.X = this->GetActorLocation().X + y * 96.0f;
 			SpawnVector.Z = this->GetActorLocation().Z;
 
 			ABSPLevelCell* cell = world->SpawnActor<ABSPLevelCell>(SpawnVector, FRotator(0, 0, 0), SpawnParams);
                    //When I take this line out its not slow
 			UGameplayStatics::FinishSpawningActor(cell, FTransform());
 			double random = ((double)rand() / (RAND_MAX));
 			cell->Type = ABSPLevelCell::LevelCellTypeWall;
 			cell->GridCoordinate = FVector2D(x, y);
 			cell->AttachRootComponentToActor(this);
 			grid[x].columns.Add(cell);
 		}
 
 	}

And here ABSPLevelCell.h:

class ABSPLevelCell : public ALevelCell
{
	GENERATED_UCLASS_BODY()
		
	void createStaticMeshWithGrid(TArray<UBSPGridRow> grid, UStaticMesh* cableHolderMesh, UMaterial *cableMat);
	
	UClass *lightClass;
    UClass *meshClass;

	
};

And here the Constructor:

ABSPLevelCell::ABSPLevelCell(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

	static ConstructorHelpers::FObjectFinder<UBlueprint> ItemBlueprint(TEXT("Blueprint'/Game/Blueprints/BSPWallLight.BSPWallLight'"));
	if (ItemBlueprint.Object){
		lightClass = (UClass*)ItemBlueprint.Object->GeneratedClass;
		
	}
    static ConstructorHelpers::FObjectFinder<UBlueprint> MeshBlueprint(TEXT("Blueprint'/Game/Blueprints/staticMesh.staticMesh'"));
	if (MeshBlueprint.Object){
		meshClass = (UClass*)ItemBlueprint.Object->GeneratedClass;
		
	}
	//Blueprint'/Game/Blueprints/staticMesh.staticMesh'
	
}

Hey, DJ_Lectr0.

I’ve been trying to reproduce your issue with little luck. There are some dependencies that prevent me from using your first code snippet. Could you give me your declarations in the class that includes your nested ‘for’ loops?

However, do these actors created in the ‘for’ loop actually have BSPs attached? BSPs are fairly inefficient, and 80 loops of 80 loops would create 6,400 of them. That would definitely explain the lagginess, albeit not why you aren’t seeing the lag in 4.2.1.

No they dont have bsps attached. And the declerations are as follows:

UCLASS()
class ABSPLevelGenerator : public ALevelGenerator
{
	GENERATED_UCLASS_BODY()

	enum SplitDirection
	{
		SplitDirectionHorizontal,
		SplitDirectionVertical
	};
	TArray<UBSPGridRow> grid;
	TArray<BSPRoomArray> roomArray;
	TArray<FRect> finalRoomArray;
	UClass *ceilingLightClass;
	UClass *exitClass;
	UClass *startClass;
	int8 loops;

	virtual void ChangeGridViaAlgorithym() override;
	
	TArray<FRect> SplitRoomRandomly(FRect room, SplitDirection previousSplitDirection, int32 stage);

	void FillOutRoom(FRect room);

	UFUNCTION(BluePrintCallable,Category = LevelGeneration )
	int32 RandomIntBetweenFloats(float float1, float float2);

	FVector2D RandomPositionInRect(FRect rect);

	void MakePathBetweenCoords(FVector2D start, FVector2D end);

	virtual void InitializeArray(UWorld *world) override;

	virtual void CreateStaticMeshes();

	virtual ABSPLevelCell* LevelCellForGridCoordinate(FVector2D Coordinate);

	UFUNCTION(BluePrintCallable, Category = Other)
	int32 getSeedForString(FString seed);

	UFUNCTION(BluePrintCallable, Category = Other)
		void openMap();
};

Also I have found out that it is actually the UGameplayStatics::FinishSpawningActor which is slow. When I take it out it works perfectly.

Hey, DJ_Lectr0, just letting you know that we’re going to follow up on this. There was a change implemented in UGameplayStatics::FinishSpawningActor in 4.3, so we’ll investigate to see if that change is what’s causing your lag. It’s unlikely we’ll know for sure until next week, however.

You only need to call UGameplayStatics::FinishSpawningActor if you are calling SpawnActorDeferred. Right now you are actually running the construction script twice, which would account for the slowness.