Download

bake light for boxes created with c++

Hi,

I wrote a class in C++ which creates 3000+ boxes from information contained in a textfile.
The App is then deployed to a daydream device.

When I open the app on the daydream device, there is always a red text visible, telling me that lighting needs to be rebuilt, even though I just did so in the editor!

Here’s my Code:
(The class VosDataManager lets me access the info about the boxes one by one. It’s essentially a wrapper around an array)


// Fill out your copyright notice in the Description page of Project Settings.

#include "VosWorldGenerator.h"
#include "VosDataManager.h"
#include "Components/BoxComponent.h"
#include "Components/StaticMeshComponent.h"
#include "Materials/MaterialInstanceDynamic.h"
#include "ConstructorHelpers.h"

// Sets default values
AVosWorldGenerator::AVosWorldGenerator()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

//Create a Root Component
UBoxComponent* BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("RootComponent"));
BoxComponent->SetMobility(EComponentMobility::Static);
RootComponent = BoxComponent;
BoxComponent->InitBoxExtent(FVector(1000.0f, 1000.0f, 1000.0f));

//get the static mesh
static ConstructorHelpers::FObjectFinder<UStaticMesh> BoxVisualAsset(TEXT("/Game/TestBox.TestBox"));
if (!BoxVisualAsset.Succeeded())
{
return;
}

VosDataManager dataMgr;
AtomData aData(0, 0, 0);
UStaticMeshComponent* BoxVisual;

uint32 count = 0;
char buf[30];

bool success = true;

while (success) {
aData = dataMgr.getNextData(success);
if (success) {
//UE_LOG(LogTemp, Warning, TEXT("aData.a = %d aData.b = %d aData.c = %f"), aData.a, aData.b, aData.c);

sprintf(buf, "Box_Number_%d", count++);
BoxVisual = CreateDefaultSubobject<UStaticMeshComponent>(buf);

BoxVisual->SetStaticMesh(BoxVisualAsset.Object);
BoxVisual->SetRelativeLocation(FVector(aData.a * 1000.0f, (aData.b - aData.a) * 1000.0f, 500.0f * (8.79455 - aData.c)));
BoxVisual->SetWorldScale3D(FVector(10.0f, 10.0f, 10.0f * (8.79455 - aData.c)));

BoxVisual->SetMobility(EComponentMobility::Static);

BoxVisual->SetupAttachment(RootComponent);
Boxes.Add(BoxVisual);
}
}

}

// Called when the game starts or when spawned
void AVosWorldGenerator::BeginPlay()
{
Super::BeginPlay();

}

// Called every frame
void AVosWorldGenerator::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

}

Any Ideas why this keeps happening?

Best regards,
Daniel

Remove this line


BoxVisual->SetMobility(EComponentMobility::Static);

Hi,

thanks, that solved the problem.
When I built the project I got a warning because the large actor might suffer from a large performance hit.
So I also added the line
BoxVisual->bCastDynamicShadow = false;

Best,
Daniel