Even Better Moon
Let’s create Moon Material first, this will have stars too. Recreating this will take you some time.
- On top we have Texture Object which is T_Sky_Stars you can find it from Engine Content.
- Which is connected to Texture Bombing, this will do some cool things with UV coordinates, it spreads stars so that the repeating pattern is not so visible.
- In left corner we have Moon texture and where CustomRotator is we have Texture Sample, this is where moon texture is.
- Moon texture settings needs to be set to Clamp.
- Material is Unlit and Masked. Enable Use Material Attributes.
- Name this as M_SkyMaterial.
- Enable Use Material Attributes (from material details panel, near Two Sided).
Set moon texture to Clamp.
Open SunSky and add SkySphereMesh. Or do what i did, open BP_Sky_Sphere (engine content) right click SkySphereMesh and copy then go to SynSky and paste.
Set material to material you just created.
In Construction Script add Create Dynamic Material Instance and assign it to variable.
Remove everything that is not in picture below.
Create MoveMoon function, this will move the texture in SkyMaterial.
Add it to UpdateSun function.
Create two variables in SunSky. StarsAreOn boolean, true by default. MaxStarsBrightness, default value is 1,5.
Now you can create two events StarsOn and StarsOff. This will control stars visibility and it will make them dissappear and appear smoothly.
These events have two Timelines. Once you add timeline double click it and find Add Float Track, name it as Drive. Add two keys:
- Time 0, Value 0.
- Time 10, Value 10.
- Set Length to 10.
Other one is just inverted.
Update SunIsDown event. So remove Moon and add Set Scalar Parameter Values.
You can do this with SetMoon but it’s not needed.
Allright, now the update should be ready. Day and Night cycle should be working, we didn’t do nothing for that. Stars should become visible right after the sun goes down. Moon should rise up too. And more importantly everything should work smoothly.
Even though everything is simulated we still hold the replication functionality. And it’s cheap!
One thing you should do is brighten up the Albedo in Volumetric Fog and modify Moon Light Intensity. Also you need UpdateSky function in BeginPlay, when game play starts it doesn’t recapture SkyLight because it’s disabled for the night (if game starts at night), it also needs a small delay.
There are some other minor problems too like when sun goes down everything gets really dark before Height Fog is turned on, so maybe somekind of another event that gets activated 2 -3 hours before SunIsDown. Anyway, i’ll leave that to you, good luck!
Really cool dude, but you didn’t tell me how do i control it in multiplayer game?
You go into PlayerController and add event which is Run On Server and Reliable. Then you use Get All Actors Of Class and find SunSky then you get the number zero out and set DN_Rules variable.
Like this:
And in widget you do this:
So best place for Execute On Server events are in PlayerController. There is a copy of every clients PlayerController in server and it’s linked to it’s owning client. PlayerController is a class and class needs to be owned by someone otherwise RPC commands don’t fully work, because some features needs to identify who is who. If you send data to server it will send it to client’s and it doesn’t ask if you want to do this it just does it, this is how the net code works in Unreal 4. If you want to use Switch Has Authority and Remote in level blueprint it won’t work because that class is not owned by anyone and therefore it can’t be identified where that remote call came from.
Extra Tips
- You can use FInterpTo or FInterToConstant to change float values smoothly, over time. Like Moon Intensity or to replace Timelines.
where did that “Update SunSky” function come from? is that an older version of Sun Position Calculator?
oh shoot posted this on the wrong page
Do you mean “Update Sky”? Because i can’t find “Update SunSky”.
Unmodified version looks like this:
In 4.26 and 4.27
This was probably made in 4.25. Because Epic added “Real Time Capture” into SkyLight
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:
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
For some reason in UE5 you can’t add Make Timespan and Date Time as they are incompatible
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/
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
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
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!
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