 Let's face it day night cycles are sick GTA has one fortnight has one scarring has one I mean even bloody Pokemon and animal crossing have them So you being the genius that you are have discovered that for a game to be truly amazing It needs to have a day night cycle and you want to add one to your game But how do I do it Shane? Well, don't you worry theoretical YouTube viewer? I'm here to show you how to quickly and easily create a day night cycle in Unreal Engine 5 Buckle up because it's death time The first thing you're going to want to do is to create a project Or if you already have one make sure it's using the default light source and skysphere blueprint provided in the editor I'm using this sexy park level. I got from the marketplace, but you can use whatever the hell you want It's your life, and I'm not gonna tell you what to do Okay, are we all on the same page? Good now select the light source and in the details panel make sure it's set to moveable It should be obvious why we're doing this because the lights going to be you know moving Next to keep things relatively simple set the rotation of the light to zero minus ninety zero And that will kind of put the Sun to midday. Okay. Now it's time to start working some magic Open the level blueprint and create a new float variable which will call Sun speed We'll use this to control you guessed it the speed of the Sun Then we'll get the Sun speed variable and compile so that we can set a value for it I'm going to go with 10 for now, but that's going to be quicker than online game is turning toxic So we'll slow it down later Now we'll compile again to save that value and create an on-event tick to trigger the updating of the rotation of the light source We'll drag out of the Delta seconds pin and create a multiply and then we'll stick the Sun speed into the other input Out of the multiply we need to create a make rotator node And we just need to change the input from x to y as we'll be rotating on the y-axis Now we need to reference the light source and to do that. I'll show you a little trick I like to use will make the level blueprint a floating window and then we'll get the light source from the world outliner And just drag it straight in how easy was that? And whilst I'm at it I'll grab the skysphere blueprint too as I'll be needing that in a minute So we've got our rotation set up But we need to make sure it's happening to the light source to do that We'll drag straight out from the light source pin and create an add-act to local rotation And then we'll take the return value of the make rotator and bug it into the Delta rotation here Now we'll connect the execution pin from the event tick to the add-act to local rotation to make sure something will actually happen Right, let's just add a comment to that because people who don't comment their code are worse than pedophiles or vegans Now we'll compile what we've got and test it out You can see that the light is moving which is good But the Sun on the skysphere is being stubborn and refusing to move So let's go and show that ignorant Sun exactly whose boss back into the level blueprint Drag out of the skysphere blueprint node and create an update Sun direction make sure to connect the execution pin and Now we'll add a comment compile and see if the Sun recognizes my authority Oh and look at it go. Yeah, you better run So this is pretty good The Sun moves across the sky the shadows change, but it never actually gets darker And we can see the light shining up through the ground after the Sun sets and that just looks stupid Let's fix it The first thing we'll do is to turn the auto exposure off so we can actually see it getting darker to do that Make sure you have a post-processing volume set to infinite extent and make sure you have the min and max brightness set to the same value I'm using a value of three for my level, but it could be different for yours Now we need to go back into the level blueprint and work some more magic So we want to make the intensity of the light go down when the Sun sets and then go back up as the Sun rises To do that we're going to check whether the rotation of the light source is greater than or less than a given value So let's get another reference to our light source and from there will create a get act of rotation and then split the struct pin as We're only interested in what the y-axis is doing from the y-axis pin We're going to create a float greater than float and a float less than float I already know the values I want to use so the top one will be if y is greater than minus 15 and The bottom one will be if y is less than minus 16 You might want to try different values, but this worked a bloody treat for me Now we're going to use these conditions for a couple of branches The first one will have from the greater than and then we'll create another one from the less than then we'll connect the execution pins So we're going to check if it's greater than minus 15 first and if that's false Then we'll check if it's less than minus 16 Next we'll create a timeline to control the transition of the light Double-click on the timeline to edit it and then we'll add a new float track Add a keyframe at zero and set the value to zero and another at five and set the value to one You can even smooth the curve out a little if you like Then we go back to the event graph and we'll say that if the first branch is true We'll play the timeline and if it's false we'll still play the timeline But in reverse But this would actually be a bit of a car crash as it is because we're doing this every tick So for every tick that our conditions are true the timeline would be played That's not what we want We just want the lighting to change the first time the conditions become true So to achieve that we'll add a do once in between each branch and the timeline and then we'll say that once the timeline Has been played through it can reset the do once nodes so they're ready to fire off again So we'll go from finished to reset for that and To make sure that they both get done We'll add a sequence and from zero will reset the first do once and from one will reset the other Okay, we're getting close now Let's get a reference to the light source and from that we want to set intensity for the new intensity input We're going to create alert for value a we're going to set it to the current intensity of the light Which in my case is 15 and for value B. We're going to get it to being dark I'm going to use zero point zero one because using zero makes the sky sphere glow in a weird way Which kind of looks wrong notice that we're starting at 15 and going down to zero point zero one That's because the timeline goes from zero to one So in this case zero on the timeline is a light intensity of 15 and one on the timeline is the light intensity of 0.01 and we'll connect the cycle output from the timeline to the alpha of the alert to drive the change in the lights intensity Then I'll connect the execution pin from the update of the timeline to the set intensity for the light source I could leave it there But it just doesn't quite get dark enough for me because of the skylights in my level So I'm going to repeat the process again I'll get a reference to the skylight create a set intensity node Add a look using values of one and zero point two for this one and then add the execution pin Then we'll just slow it down a little using the Sunspeed variable before compiling and then we can test it out As you can see it looks well sexy The shadows are moving slowly across the ground the color of the sky changes It gets dark after sunset and the stars come out at night Perfect. So we're done here if you found this video helpful then be a legend and hit the thumbs up and subscribe buttons It really helps me out. I have links to my discord server and patreon pages in the description If you want to get more involved and I'll also throw a link to the level I use for the exercise down there too All that's left to say is thanks for watching and class dismissed