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.
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.
- You can use FInterpTo or FInterToConstant to change float values smoothly, over time. Like Moon Intensity or to replace Timelines.