Skip to content

UE4 – Day and Night Cycle for Multiplayer (Part 1)

Moon and Fog

In SunSky add Directional Light and name it as MoonLight.

Set intensity to 0 and temperature to 4000.

Add arrow and drag it in MoonLight.

Add Spring arm and drag it in Arrow.

Rotate Spring Arm 180 degrees, set arm length to 50000 and disable Do Collision Test.

Add Exponential Height Fog.

Copy the values from below.

  • Fog Density 0,05
  • Volumetrig Fog Albedo is #4C4C4CFF (linear)
  • Scattering Distribution 0,9
  • Extinction Scale 15
  • Hidden in Game denabled

Increasing Extinction Scale the fog gets thicker. You don’t wan’t to touch anything else.

Add Sphere mesh and drag it in Spring arm.

Disable collision and cast shadows.

Create Material for moon and…

use material instance of it.

Go to UpdateSun function, add SetWorldRotation for moon light after directional light rotation. Use Directional Light rotator and invert the face so the moon is pointing from opposite side of sun. Even though that is not moons path in real life.

SetMoon event comes here and it changes scale and distance.

Continue SunIsDown event by adding the rest:

You may notice a small jittering or lag, when sun is up, sometimes shadows jump back. This is because a massive static mesh is moving every frame. It’s basically just spam. Even though the Moon is set to Hidden it still does this. If you find BP_Sky_Sphere blueprint from Engine Content and open it you’ll see that SkySphereMesh mobility is set to static. We don’t want massive objects to be movable. So the only way to fix this is to create Sky Sphere and Material where we have a Moon texture moving on the surface.

Pages: 1 2 3 4
Subscribe
Notify of
10 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
kilokillzall

where did that “Update SunSky” function come from? is that an older version of Sun Position Calculator?

kilokillzall

oh shoot posted this on the wrong page

lvlmaster

Do you mean “Update Sky”? Because i can’t find “Update SunSky”.

Unmodified version looks like this:
comment image
In 4.26 and 4.27

This was probably made in 4.25. Because Epic added “Real Time Capture” into SkyLight
comment image

https://docs.unrealengine.com/4.27/en-US/WhatsNew/Builds/ReleaseNotes/4_26/#real-timeskylightcapture

Which is why “Update Sky” is not in 4.26 and latest:
comment image

bonkimaslo

Do you think this will be the proper system for Unreal Engine 5 as well? Or did they add some new way to do it even better?
Thanks for your hard work

bonkimaslo

For some reason in UE5 you can’t add Make Timespan and Date Time as they are incompatible

lvlmaster

Make sure you got the variable type right, best way to do variables is to use “Promote to Variable” which you can get by pulling out from endpoint.
In this case find AsTimespawn (text) or AsTime (text) and try pulling out from these to create variables.

https://docs.unrealengine.com/4.26/en-US/BlueprintAPI/Utilities/Text/AsTime/

https://docs.unrealengine.com/4.26/en-US/BlueprintAPI/Utilities/Text/AsTimespan/

bonkimaslo

Thanks for the quick responses, appreciate it!

It seems like a UE5 bug to be honest.
When I drag Server Game Time to A position (Date Time structure) of the ADD node, the B position shows that it’s timespan structure, which it should be. But when I connect the Make Timespan endpoint to it, the A (Server Game Time) connection is broken, and it changes every pins structure type to timespan.
I found some other post showing the same problem :
https://forums.unrealengine.com/t/adding-timespan-to-date-time-not-working/256329

Sorry to spam your tutorial about UE5 stuff, I might have to build it in UE4 and migrate to UE5 to make it work

lvlmaster

Oh yeah, i found the same thing from UE5 EA2, it’s actually missing Date Time and Timespan combining/add node.

You could create Blueprint Function Library in C++ and then create custom function which combines them and returns result or… just try the full C++ version:
https://levelparadox.com/2020/11/13/ue4-day-and-night-cycle-c-part-2/

you just need to create material, material instance and 2 curves and it should work out of box.

Add me on Discord if you need more help: nuclearlocket#9741

bonkimaslo

Haha, I waited with messing around with it until the actual release of UE5, but it seems like they didn’t fix this issue, this node is still bugged for me.
I have no experience with C++ in Unreal, but gonna give it a shot, thanks!

lvlmaster

Well haven’t seen anything new or better anywhere else and seem’s like everyone else is also using Sun Position Plugin tools to do Day Night Cycle in UE5. Even in UE5 + Lumen you still need Sun Position Plugin, Exponential Height Fog and Sky Athmosphere if you wan’t Dynamic Day Night Cycle.

This project in UE5:
https://www.youtube.com/watch?v=nkPnIlPtg8Y

Someone else using Sun Position Plugin in UE5:
https://www.youtube.com/watch?v=kcV5XOqX9i8

Level Paradox
10
0
Would love your thoughts, please comment.x
()
x