I am currently trying to make a stealth component for my game in which I want to access the static light information held in the Precompiled Light Volume. I notice the method called InterpolateIrradianceToPoint() inside the FPrecompiledLightVolume Class, however my engine hard crashes on using this function.
I assumed it might be because the Precompiled Light Volume wasn’t initialized and I found that basically the data is not accessible for the level
This is my code:
void UTestLighting::CheckLight() {
UWorld *World = GetWorld();
if (!World) {
UE_LOG(LogTemp, Error, TEXT("World Not Initialized"));
return;
}
ULevel *Level = World->PersistentLevel;
if (!Level) {
UE_LOG(LogTemp, Error, TEXT("Level Not Initialized"));
return;
}
FPrecomputedLightVolume *Volume = Level->PrecomputedLightVolume;
if (!Volume) {
UE_LOG(LogTemp, Error, TEXT("Volume Not Found"));
return;
}
//FVector WorldPosition = GetComponentLocation();
//float AccumulateWeight = 0.f;
//float AccumulatedDirectionalLightShadowing = 0.f;
//FSHVectorRGB3 AccumulatedIncidentRadiance;
//FVector SkyBentNormal = FVector::ZeroVector;
UMapBuildDataRegistry *BuildData= Level->MapBuildData;
if (!BuildData) {
UE_LOG(LogTemp, Error, TEXT("BuildDataMap not Found"));
return;
}
FPrecomputedLightVolumeData *VolumeData = BuildData->GetLevelPrecomputedLightVolumeBuildData(Level->LevelBuildDataId);
if (!VolumeData) {
UE_LOG(LogTemp, Error, TEXT("BuildData not Found"));
return;
}
if (Volume->IsAddedToScene()) {
UE_LOG(LogTemp, Error, TEXT("Not Added to Scene"));
return;
} else {
//Volume->InterpolateIncidentRadiancePoint(WorldPosition,
// AccumulateWeight,
// AccumulatedDirectionalLightShadowing,
// AccumulatedIncidentRadiance,
// SkyBentNormal);
//
}
if (Volume->Data == nullptr) {
Volume->SetData(VolumeData, World->Scene);
UE_LOG(LogTemp, Error, TEXT("VolumeData Not Found"));
return;
} else {
if (!Volume->Data->IsInitialized()) {
UE_LOG(LogTemp, Error, TEXT("VolumeData Not Initialized"));
return;
}
}
}
The function has been commented out for testing purposes and the output of this function currently is “BuildData not Found” I have made sure that static lighting is enabled in my project as well as have built and saved the lighting in my level. I am assuming that this is why the engine crashes
This is for a project that is using Unreal Engine 4.27 I was wondering if anyone had any suggestions for how to get around this issue.