Getting a light reference from the scene

For such a simple problem, I have wasted so much time and am no closer to finding an answer.

I have a blueprint (pictured below):

I am trying to convert this to C++… but I have a problem getting a reference to the sky light in the scene. As you can see in the blueprint, the type is “Sky Light” which then I get the light component of, and set its intensity. In C++, it seems there is only a variable type for the skylight component, not the skylight scene object…?

In any case, I created a sky light component var in C++ and tried to set it from within the editor

Property def in C++ class

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = References)
USkyLightComponent* SkyLightRef;

So e.g. goal would be the following code working to turn off the sky light:


…except I have no way to set the variable within the editor the the sky light that’s in the scene. It’s value is “none” and I can’t change it to anything else.

In the blueprint editor where you select the variable type you can choose between Sky Light and Sky Light Component, the first one is the ASkyLight Actor placed in your scene/level, the latter the type of component used/attached.
Change your C++ SkyLightRef variable to type ASkyLight*. From there you can check whether SkyLightRef != nullptr, then call SkyLightRef->GetLightComponent(), check it against nullptr and finally call SetIntensity.