I’m trying to find the correct way to instance a BP actor through C++. My original method of spawning my world causes an incredible amount of lag on even a high end system due to draw calls, but I’ve been unable to find a working way to instance everything and limit the lag.
I’m currently doing
protected:
UPROPERTY(EditDefaultsOnly)
TSubclassOf<ATile> tile; //Base tile object
void ATileManager::SpawnTestWorld()
{
FActorSpawnParameters spawnParams;
spawnParams.Owner = this;
for (int y = 0; y < WorldLength; y++)
{
for (int x = 0; x < WorldWidth; x++)
{
AActor* spawnedTile = GetWorld()->SpawnActor<ATile>(tile, FVector(x * TileWidth, y *TileWidth, 0), FRotator::ZeroRotator, spawnParams);
}
}
Obviously this isn’t efficient, and a 100x100 map drops my fps from 120 → 15-30.
I know I have to add an UInstancedStaticMeshComponent to my class, but I am unsure of how to utilize it from there.
Any help would be appreciated,
Thank you