Hi!
I’m doing the designer of buildings from blocks of StaticMeshComponent.
When I perform “build all levels” I catch following messages:
Performance Warning Builder10 Large actor receives a pre-shadow and will cause an extreme performance hit unless bCastDynamicShadow is set to false.
For avoid this I set mobility for all UStaticMeshComponent as EComponentMobility::Static, after this performance warning is disappears, but even after “build all levels” I see message when start play in editor: “Ligth need to be rebuild (75 units objects)”. 75 is amount of StaticMeshComponents.
Example of my code:
ABuildCreater::ABuildCreater(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
PrimaryActorTick.bCanEverTick = false;
static ConstructorHelpers::FObjectFinder<UStaticMesh> LevelWallAsset(TEXT("StaticMesh'/Game/Geometry/Meshes/Levels/3'"));
LevelMesh = LevelWallAsset.Object;
}
void ABuildCreater::BeginPlay()
{
Super::BeginPlay();
MakeBuild();
}
void ABuildCreater::OnConstruction(const FTransform & Transform)
{
Super::OnConstruction(Transform);
MakeBuild();
}
void ABuildCreater::MakeBuild()
{
for (auto i = 0; i < LevelAmount; i++)
{
// not importatnd code for position of level
BuildLevel(level_shift, FRotator(0.0f, r, 0.0f), level_scale);
};
}
void ABuildCreater::BuildLevel(const FVector& location, const FRotator& rotator, const FVector& scale)
{
auto LevelComponent = NewObject<USceneComponent>(this);
LevelComponent->CreationMethod = EComponentCreationMethod::UserConstructionScript;
LevelComponent->SetRelativeTransform(FTransform(rotator, location, scale));
LevelComponent->AttachTo(RootComponent);
LevelComponent->RegisterComponent();
CreateLevelPart(RootComponent, FTransform(rotator, location, scale), LevelMesh);
}
void ABuildCreater::CreateLevelPart(USceneComponent* Level, FTransform tranform, UStaticMesh* LevelMesh)
{
auto LevelPart = NewObject<UStaticMeshComponent>(this);
LevelPart->CreationMethod = EComponentCreationMethod::UserConstructionScript;
//LevelPart->bCastDynamicShadow = false;
LevelPart->AttachTo(Level);
LevelPart->SetStaticMesh(LevelMesh);
LevelPart->SetMobility(EComponentMobility::Static);
LevelPart->SetRelativeTransform(tranform);
LevelPart->RegisterComponent();
}