In this lesson, you will learn how to synchronize your scene’s celestial rotation with atmospheric properties to create a cohesive, real-time lighting cycle.
The Logic of Celestial Synchronization
An effective Time of Day (ToD) system is essentially a mapping exercise. You are taking a single variable—a "Time" float ranging from 0 to 24—and using it to drive the transformation of your Directional Light and the density parameters of your Sky Atmosphere component.
To keep your environment looking physically grounded, you must link the sun's pitch to the atmospheric transitions. When the sun is at a low angle (sunrise/sunset), the light path through the atmosphere is longer, resulting in increased Rayleigh scattering (the "reddening" of the sky).
Implementing the Cycle
Instead of manually updating components, create an Actor Blueprint that holds a reference to your DirectionalLight and SkyAtmosphere. Use a Timeline or a Tick function to increment a CurrentTime variable.
Use the CurrentTime to calculate a rotation value for your light, then map that same value to the atmospheric parameters. Here is a simplified logic flow for the rotation:
// Convert 0-24 hour time to 0-360 degrees
float SunAngle = (CurrentTime / 24.0f) * 360.0f;
DirectionalLight->SetActorRotation(FRotator(SunAngle, 0.0f, 0.0f));
While the light rotates, you must concurrently update the SkyAtmosphere properties. Specifically, you should adjust the MultiScatteringContribution and GroundAlbedo based on the sun's elevation. If your sun is below the horizon (nighttime), you should programmatically reduce the intensity of your Directional Light to near zero while simultaneously increasing the SkyAtmosphere moon-light contribution to maintain ambient visibility.
Connecting to Volumetrics
Because you have already mastered Volumetric Clouds and Volumetric Fog, ensure these components are also bound to the CurrentTime variable. By scaling the FogDensity in response to the sun's position, you can simulate the cooling of the earth at night, which naturally causes ground fog to settle. This creates a seamless transition where the lighting, sky color, and depth-haze evolve as one unified system rather than disjointed effects.
Key Takeaway: A professional Time of Day system relies on a single master time variable driving the math for rotation, atmospheric scattering, and volumetric density in perfect unison.