Download

Atmospheric Fog and Directional Lighting not working together correctly in my custom Actor class

I made a quick 1:15 video outlining my problem because I feel this needs the visuals to help explain the issue.

[video]http://tinypic.com/r/24133nr/9[/video]

Also, just FYI, the spawned lighting and fog in my class, other than changing the light to atmospheric sun light, everything is left to default settings.

Try attaching the DirectionalLightComponent (WorldLight) to the hierarchy (RootComponent/AtmosphereFog).

As not a direct answer for you, I have a workaround approach that may be more beneficial, if your only goal is to modify atmosphere through code.

If you create a class that extends LevelScriptActor, you’ll be able to reparent your level blueprint to your custom class. You can then create properties like this:


	UPROPERTY(EditAnywhere, Category = "AKQ") ADirectionalLight* LightSource;
	UPROPERTY(EditAnywhere, Category = "AKQ") AExponentialHeightFog* Heightfog;
	UPROPERTY(EditAnywhere, Category = "AKQ") ASkyLight* SkyLight;

Reparent your level blueprint to your class and you’ll see this in it:

Where you can directly select the light/fog actors that exist on your stage.

This way you still have 100% access to them through code, with the benefit of them also being on your stage, and not having to work in darkness.

Of course, if you do need to create them manually, then sorry my post won’t help.

No, sir. That made no difference. I’ve made both World Light and AtmosphereFog the root components, neither with any differing result.

Not quite, Juice. My goal is to create an self-contained atmosphere class that contains all the common tools to create an environment’s atmosphere, so that a player can edit them in real time. I don’t want them exposed in the editor though.

Okay, so I’ve figured out what the actual problem is… just don’t know the solution

The Atmosphere Fog isn’t rendering at all… all the effects that were working were the directional light and the height fog…

The atmosphere fog is loading into the level, but for whatever reason beyond my understanding, it’s not affecting the scene in any way, including the sun disc, etc.

Only one component can be the root component. So if you do this


//.cpp
AAtmosphere::AAtmosphere()
{
	//...
	SetRootComponent(AtmosphereFog);
	//...
	SetRootComponent(WorldLight);
	//...
}

the first time you set the root component will effectively do nothing because you override it with the second call.

What I meant with attach it to the hierarchy is this


//.cpp
AAtmosphere::AAtmosphere()
{
	//...
	SetRootComponent(AtmosphereFog);
	//...
	WorldLight->AttachTo(AtmosphereFog); //NOTE: AttachTo may have changed in 4.12/4.13 but should work in 4.11
	//...
}

Lol I understand what you mean. I meant that I tried your example. Then tried to set the other component as root instead.
Neither had any effect.

Did you find a solution to this? I’m having the same problem and can’t find the answer

You are absolutely correct, and this issue hasn’t been addressed for years. It still exists in 4.19. I forgot about it, until recently coming back to work on a robust atmosphere, day/night, etc. system I’ve been tinkering with for a long time. I’ve always hit a wall at this point, and get insanely annoyed that I can’t utilized atmospheric fog at the component level. It has nothing to do with hierarchy in the component chain, and running StartPrecompute after setting up some defaults doesn’t do a thing either. Only thing that shows is the sun disc. “Sky” is black, I don’t even get ground scatter (that I notice, anyway).

I think the atmosphere stuff needs some attention. Being able to get colors would be nice, as requested every now and then by others. Being able to explicitly set the dominant directional light would be nice too (as opposed to checking that box in the directional light). Heck, we can’t even set that variable on a directional light, only get it. So that needs some love too.

Edit:

I stand corrected, literally moments after posting this. I had set DistanceScale to 10000 (or 1km) vs the default of 1. This is because I intend to have large/long distance scenes, and per the documentation on DistanceScale:


Controls a distance factor. The default value of 1 assumes a 1:1 scale of Unreal Units to centimeters.
This makes for a very small world. As your world size increases, you will want to increase this
value accordingly. Larger values cause changes in the fog attenuation to occur more quickly.

Now if I set it in the BP, the default, that is… It doesn’t work. But if I make a variable, make the default for that 1, I can tweak in the editor and it works. Change the default in the BP, and it breaks if it’s anything other than 1.