Accessing Static Light Information from C++

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.

I made some progress on this question. It would seem I was looking at the wrong thing and conflated PrecomputedLightVolume with PrecomputedVolumetricLightmap. If you wish to access the PrecomputedLightVolume, you have to change World Settings->Lightmass->Volume Lighting Method to Sparse Volume Lighting Samples.

The following is the code to a function that should output “LightVolume not added to scene” or “VolumetricLightmap not added to scene” corresponding to the above mentioned setting.

void UTestLighting::CheckLight() {
    ULevel *Level = GetComponentLevel();
    FPrecomputedLightVolume *Volume = GetWorld()->GetCurrentLevel()->PrecomputedLightVolume;
    FPrecomputedVolumetricLightmap *VolumetricLightmap = GetWorld()->GetCurrentLevel()->PrecomputedVolumetricLightmap;

    if (!Volume) {
        UE_LOG(LogTemp, Warning, TEXT("Volume returned Null"));
        return;
    }

    if (!VolumetricLightmap) {
        UE_LOG(LogTemp, Warning, TEXT("Volumetric Lightmap returned Null"));
        return;
    }

    if (!VolumetricLightmap->IsAddedToScene()) {
        UE_LOG(LogTemp, Warning, TEXT("VolumetricLightmap not added to Scene"));
    }

    if (!Volume->IsAddedToScene()) {
        UE_LOG(LogTemp, Warning, TEXT("LightVolume not added to Scene"));
    }
}

I will continue looking into this as I believe that Volumetric Lightmaps give a better visual representation of light, however I am not currently sure how to query them for specific information at a point in world space.

I’m open to suggestions should anyone come through here and find this.