[TUTORIAL] Quick Time-of-Day Setup

Never mind i just found color curves default values were set to none. is why its always good to pay attention to log errors…lol

Just downloaded updated BP wow its so clean in there now!

@Keeperofstars, I didn’t add a moon because you’re only allowed to have one directional lamp per scene, so it’s tricky. You’d have to use same lamp for both sun and moon.

@Shoiko, well, I was inspired by screenshots you posted earlier of your version :slight_smile: And I also wanted it to be easily readable if I was going to publish it.

are you just allowed one, or only one affecting lighting? Would you be able to have two and toggle which one had effect? I could see challenge with dusk and dawn though, but if you just have moon appear and dis-appear a bit off of dusk /dawn time frame, could work decently. Or would it be possible to have a heaving night light value, even if semi static in position or allow player to set angle, that provided light at night, as to prevent it from full day to pitch black? Wouldn’t need to exactly be moving dynamically but could provide a bit of lighting. But I’ll have to go back and read light section documents again. I thought it was just 1 directional light affecting. Granted since you have light tied to sky that makes things a bit tricker would need to figure a way to swap them run time without it looking glitchy. Can see where it’s not at all an easy task though.

@Keepers
Theres plenty that you can do, currently I have a static skylight that is set to 0.1 to add minor ambiance and it seems to work at night too. Theres many different ways to get working.

@greg
I see time is going in reverse, I havnt tried to fix it yet but I’ll post it here if you havnt already fixed it.

Great work so far guys! Perfect tutorial . I was stuck trying to figure out time-of-day and worked with exceptional ease.

Also, very happy to see community working together with tutorial!

:frowning: Yup, 4.2 seems to have broken it. rotator mathematics are messed up, I’ll fix it and post updated version when I get . Thanks for catching !

Also, does anybody have any input on stuck-at-noon problem? Because it does still happen when you set day-cycle time high (~100), and I’m stumped.

I’m pretty sure you’re experiencing gimbal lock by adding rotation to directional light. I can take a closer look Thursday if not sooner. Fantastic BP BTW. I had created a similar one driven by a Timeline, but I really like way you have incorporated color curves.

Alrighty, I’ve found a solution! (ty to lbraud for idea ;))

In skydome BP construction script, find commented section that says “Set sun’s pitch based on “Default Hour”” (it will be near left side). Then go “Make Rot” node in that section. Set “Roll” input value for node to equal 1 (by default it will be zero).

should eliminate it getting stuck. I don’t know if is right way to fix gimbal lock, or if there’s a better method, but it works :slight_smile: (If somebody does know a better method, please tell me!)

I’ve added a second direction light for a moon and just added sun and moon to original BP component. I need to also add a skylight to make even normal looking lighting as well. I’m going to add some dynamic atmosphere when i get on as well. heres a SS of night:

Also time is that our pitch goes from up and down in undesired rotations for what you want. I’m going to change it to calculate total rotation of sun based on a 360 movement. What you are getting now is something like a rotation of -90 to +90 and after noon +90 to -90 which breaks time calcs it seems.

Okay, I’ve fixed it! I’ve actually overhauled whole way time and rotation was calculated. Time is done first, then sun’s rotation is changed after that. I’ve also condensed everything into multiple functions, to improve readability. Check it out for yourselves!

Get new version here: Greg's Blog: UE4 Time of Day Setup

I’ve made a blog to make it easier to update. Also, I’m hosting file on google drive, so DL is a bit wonky (you have to go file-download after you click link). I don’t want a ton of ads and stuff though, so it’s best I could find :slight_smile:

EDIT: Just wanted to note that by default, time moves very slowly. Increase “Time Speed” to something like 1000 to fix :slight_smile:

EDIT2: @Shoiko, wait you are right, two sunlamps are possible! is awesome news to me, I guess my earlier tests were mistaken. :slight_smile:

I really like how you’ve broken blueprint up into different functions. makes it much easier for me to follow.

I have some suggestions for public variables that show up in editor:

* Day Cycle Time can be removed.

* I would move "Use24HrDay" and "Display World Time" to a new "Debug" category in order to clean up  "Time of Day" category.

* I think  scale of "Time Speed" is too small. Would a level designer really want to set  length of day down to  minute?  Number of real minutes in one game day would give you a scale of 1 to 1440. Currently  scale is 1 to 86,400 (assuming real-time is  maximum).

* You could get rid of "Use Day/Night" check box. If  level designer wasn't going to use  day/night cycle, then they wouldn't use  blueprint. Perhaps  is for testing. If that's  case, then it too could be put in  debug section.

Again these are just suggestions, do what you will! :smiley:

I’m still puzzled about sun getting stuck in sky. I was about to make a test when I decided to check thread first. I’m glad you were able to fix it. One question I have is why do other two axes flip 180 degrees when you add more than 90 degrees to third axis? You can do in a blank project with any Actor. To test, if you set DirectionalLight’s rotation to (0,0,0) in Transform section of editor, then drag Y to 80, both X and Z stay same. If you instead drag it to 95, X and Z flip to 180 and Y becomes 85. Why does happen? Wouldn’t throw off any “math” you were trying to perform in a blueprint? I think is intended behavior of adding rotation, but I don’t understand why.

I’m loving blueprint and community involvement. How can I help you to improve it?

Yep, I had a “D’oh!” moment after realizing I had left it in there when I uploaded it. I’ll fix it for next release (hopefully not toooo far away :))

I’m not 100 percent sure what you mean here. is basically a ratio of gametime:realworldtime. For instance, setting it to 1 will give you 24hr days. Setting it to 4 will make 4 game minutes pass in 1 real world minute, so you’d have 6 hr days. If isn’t very clear then maybe I should change it back to old way :slight_smile:

I do actually agree with , as well as other suggestions about debug section. Cleaner is always better!

is some weird engine-defined behavior. I’ve noticed it too, it’s annoying. Also fact that sometimes it will change 0 to something like 0.000000017 for no apparent reason. I would think it’s to avoid gimbal lock, but it obviously still happens xD

Maybe related to : I believe that UE4 uses +180 and -180, not full 360 rotation. I think I heard that in one of their tutorials (can’t remember which one unfortunately). I also saw it when I was logging rotation of my sun a while back. If there are any Epic devs here, comments on all rotation stuff are welcome!

Anyway, I’ve changed my BP to clear and set rotation every frame, instead of adding it. Seems to work much better, much less glitchy.

Well, your suggestions and comments are helping a lot! It’s always awesome to get feedback from a mind other than your own. Amazing how many things one misses :slight_smile:

Also, how do you guys think I should do moon? Should it move at all, should it do a full circle or just move a bit…? (Thanks to Shoiko btw for showing me that moons are a possibility!)

i have it moving im caught up in moving so i haven’t done much but one thing i had to do was during day slow rotation of moon and speed up rotation at night is to insure moon rotates out of view before sun takes moon sun target. other wise mood would appear to blink away. Also added a skylight to help with night and day ambient light.

I also updated constructor and added functions to make script smaller. I don’t have you last changes yet but here’s what i got its not much:

https://.co.nz/#!IoBXCDSR!Nh3w2itPq31_wmZUlAy9UQvbAtvTH2956KIH8m1qko8

Ah, I see you moved all lights into one blueprint. I tried doing , but then it’s not possible to change sun’s settings per map, that’s why I chose to leave them separate. I find it causes less problems to assign your own light actors in each map; I couldn’t actually get your lights working in my map.

Also, I believe skylights are static-only, which might not work to well with a full day/night cycle. I think and ambient cubemap might be better, but those are set in post-process, making it hard for a blueprint to access them. Tradeoffs… :frowning:

On another note… is it possible to make custom templates sharable on web? It would be much easier to say “download template” than to say “download blueprint, then replace old one, then set sun property…” Just a thought.

Once you drop a instance of your BP onto a map then you can select that object and make changes per instance on field. Just like when I have one monster character that will house all my monster types. Once you drop it into field I can configure each to be different but behavior of attached BP will be same outside of dynamically loaded Behavior trees/mesh/animation BP

As for sky light it is dynamically affecting my ambiance of my scene in real time I don’t have code in there but i had skylight changing at night gradually to have a portion of night where map was almost completely dark and as moon moved across sky it got gradually brighter.

As for temples i have no idea.

But AFAIK you can’t change settings for components of blueprints per-instance (can you?). For example, in your blueprint, can you change sun’s shadow-casting settings in each instance?

You are correct but Likewise you can expose desired configurations to Details tab and constructor for that instance can be used to modify said desired changes. Like we do already for position rotation etc. Anything is possible really.

Yes, that is true. IMO it’s not worth it though, it’s a lot of work to set every property manually in constructor, and you still might miss something that somebody else would want to set. I prefer keeping lamps out of BP. Just my opinion though :slight_smile: