Day-Night Cycle questions

Hey everyone,

I’ve been researching a lot on day-night cycles in UE4 recently, but I can not seem to get it working just right once I do it myself.

Does anyone have any recommendations on videos I could follow or methods to get the brightness and appearance of the day a night to look decent & transition smoothly?

Thank you in advance!

Hey there @EnragedRavioli! As always the wonderful Matt Aspland has an excellent tutorial on getting basic cycle done. It’s very quick, easy, and looks decent. You’d definitely have to extend it a bit to get it looking great, but it’s a good start!

Disclaimer: Epic Games is not liable for anything that occurs outside of this domain. Please exercise good judgement following links outside of the forums.

2 Likes

Hey @EnragedRavioli!

To add on a bit more to @SupportiveEntity, if you are looking for exact accuracy in position depending on the hour of day that looks great or to simplify a 24 hour timeline, I highly suggest the built in Sun Position Calculator. Here is a great video from Unreal for setting it up with an example use case, and you can lerp through the hours using a similar method to the above:

Hope the above helps get you get the effect you are looking for!

3 Likes

Hey @EnragedRavioli!

Checking in! Did one of the above posts solve the problem you were facing?

I’m mid working on it! I can’t say for sure than any of them has specifically solved my issue but I’ll make sure to mark it as solved whenever I figure it out!

1 Like

Hey again!

I’ve started looking into this problem again and I just wanted to ask you something regarding the video you suggested… The sun position calculator plugin seems to be the perfect tool for me to get this Day-Night Cycle right, but I’m coming across this issue I can’t seem to get around:

I can not seem to attach my Sky Sphere to the SunPosition BP, and, therefore, it currently doesn’t control my sunlight or do anything for that purpose…

Would you be able to help me figure out the reason?

Hey @EnragedRavioli,

That is super odd. It should automatically have read your BP_ Sky_Sphere. Does this still do the same thing on a new level? I did notice that your sky sphere shows up differently, was this sky sphere manually added or altered?

UE4Editor_9JlZL33203

Any additional specifics will be appreciated in figuring this out!

Yes, I did manually add the sky sphere, I’m assuming that’s what’s causing the issue since I can’t find any resources on this…

Do you believe there is any way of getting around it with my manually added sky sphere or would I have to try it on a separate level to get it to work?

Edit: The reason I added my sky sphere manually is because I read somewhere than once you alter the BP for one project you alter it for every project, for which someone recommended duplicating my sky sphere or something similar… I can’t quite remember why…

Hey @EnragedRavioli,

Super odd. So I even tried on a blank level and the BP_Sky_Sphere worked if either one was placed first (sun position calculator or sky sphere.)

Has they sky sphere been altered? Is the one you are using a duplicate? That is most likely the reason why it may not be working.

I would open a new level (both default and empty) and see if that makes a difference, and if the level may be bugged out somehow.

Hopefully the above narrows down what the issue could be and we can get this solved!

1 Like

Quick update!

It was indeed because I had duplicated my SkySphere BP. I ended up deleting the duplicated SkySphere and replacing it with the default one.

Most people will probably not come across this issue, but if you do, there you go!

Thank you Quetz, I’ll make sure to let you know if I come across any most issues when working on the Day Night Cycle!

After following Matt Aspland’s DayNight Cycle tutorial I’ve got a semi good looking day and night cycle working (although it doesn’t seem to be nearly as dark as I want it to be, but that’s something I’ll probably be able to figure out myself)…

How would you suggest I would go about connecting the sun position calculator plugin into my day night cycle in order to have an idea of what time it should be in-game?

Most importantly I’d like to figure out how I’d be able to set the length of the day and night in minutes instead of using the speed variable Matt uses in his video:

Screenshot_5

Thanks in advance!

Hey @EnragedRavioli,

Here is a blueprint example using a similar method to Matt’s using the only the hours in the sun position calculator and a blueprint actor (I would avoid using the level blueprint if you can and this also means you can take it from level to level).

The sun will move one hours position after every second. (Delay works in seconds). And this can get accurate down to the second if you expand it. So I suggest planing how long each minute is going to be in seconds, and that should help out your day and night cycle. EX: One minute = 1 second so each hour is 60 seconds, etc.

This is also written in such a way that if you would like to modify this to branch a different delay depending on the time values it is possible.

I hope the above helps get you where you want to be!

1 Like

Folks, maybe before suggesting random stuff to end users you should ask what their purpose is.

For a game? The sun position calculator, though nice, is probably overkill.

For archviz, that’s not too bad. But also not very accurate unforturnately.

Second.
Assuming that he needs the day cycle to function in a game, there’s a couple of things that should happen.

  1. revert to the old skysphere BP, because the new system sucks more fps than a ford bronco eats gasoline.

  2. 90% or more of tutorials do it 100% wrong.
    You need to create a localized instance of the skysphere BP, or else you modify all engine projects.

  3. And pertinent to the last question.

You also have to modify your skylight or recapture it in order to get the correct lighting in your scene.

With ue4 .22 there was a bug/ish situation where the skylight cannot capture in realitme.

The issue may have persisted into .27. Not sure.
If the skylight has a checkbox for realtime capture, thata all you need to do.

Otherwise you have to compile from source and modify the skylight to actually capture in realtime. The system it was using was causing unwanted game thread hangs.

  1. Performance.
    Its a lot cheaper to make the sky material handle sun disk and moon disk than it is to render the object(s) themselves.
    Howver you do have to study up on what Declination, RightAscention, and maybe even Julian Date are on order to sort things out.

While the sun calculator essentially just does it wrong, its very possible to simulate accurate daytime to specific date in time - past or future - with an astounding 90% or more accuracy and a relatively low MS cost.
There are some new formulas out there that while simplified provide greater accuracy overall.
But you do have to become a math nerd to implement them

3 Likes

Hey MostHost!

Thanks a lot for the in-depth tips, you’ve given me a lot of food for thought and quite a lot to work with too!

I do recall reading somewhere that editing the default sky sphere BP would modify all the engine’s projects, which is obviously not ideal but something I’m willing to do for the time being while I figure out how exactly I want my day-night cycle to look.

It is, indeed, for a game, and my biggest concern that I can’t seem to get right by following tutorials is the conversion from time in-game to seconds, minutes, and hours in real life (I’m currently trying Quetz’s method that they posted above…).

Besides this I’ve been running into some issues regarding the lighting and the appearance of my level’s sea, but that’s not my biggest priority YET. Then again, we have the performance, which I’m also not very concerned with for the time being, but will most likely look into once I have the system working as I expect it to.

Anyways, thank you for taking your time to help me out here, I really appreciate it!

Dont even bother.
You make your own clock.

First decide how many seconds you have in a day cycle. Is it realistic 1:1 or sped up?

Then just gametime ٪ total seconds
To keep the time within the day range.
Whatever the value out of that, is the “seconds” for “today”.

Then you do your math to solve sun positioning.

Assuming you are on the equator, and that the sun travels across the sky previsely (which it does not in reality even at the equator) you can simplify this out to percentages, or degrees.

your days seconds/360 = ratio of degree for each second.

That multiplied by your day’s seconds is therefore the sun rotation on a single axis.

Obviously you need proper math.

And also somewhat not obviously, the sun doesn’t rise and set at the same time.

On earth that’s caused by the tilt of earth’s axis and your position on the globe. Which is also part of what is required to calculate the path of the sun across the sky.
(Also earths rotation is not a constant, but being that we are talking microseconds of difference lets just mention that to add to people’s general knowledge?)

I would suggest you decide how to mimic the behaviours based on an oversimplification.
Pick what season your game is going into or set up a table for progression of seasons.
Choose how many days per seaon. Then pick sunrise/sunset maximums for that season.

With that range you decided:

Assume the sun position like for the equator scenario above within the initial range.
Next day, move sun set to a lesser value for winter, a higher value for summer.
(Value should be max range - prev season max range / total day of season greater or smaller).

In the end the sun rotation will always be the same, but the “time” at which it comes will now be different.

Good enough for most games.
Not good at all for realistic stuff. But we already said you need to implement real sun positions for that :wink:

Ps.
I dont think engine rotators work on degrees. Though i do seem to recall that the light vector did rotate from 0 to 360.
Anyways. You can always 2PI radians to a unit circle.
The probelm will be floating point precision if you can’t c++ and use Double.

1 Like