Adding a Day/Night Cycle in UE4 in C++
UPDATE: This method shouldn't be used anymore. Epic released an atmosphere plugin that replaces the skybox that was used in this guide. To get it working with that it just requires some small changes and I'll eventually update the post.
This code was apart of an old project of mine that never went anywhere so I figured I'd add it to an example project and release for free. Everyone could use a day/night cycle that's networked right?
This code also isn't that good, but it does work just fine. I never got around to cleaning it up so do what you want with it. The original codebase was from EpicSurvivalGameSeries.
This works for dedicated server and listen server.
- First off make sure that your Skylight and Light Source are both set to movable in your scene.
- If you don't have a GameMode and a GameState class then go ahead and make those. Remember, they have to match (GameModeBase/GameStateBase and GameMode/GameState).
- To avoid the blog post being VERY long (since I'd have to embed the code from the files) just download the header and source files DayNightGameStateBase.h, DayNightGameStateBase.cpp, DayNightGameMode.h, DayNightGameMode.cpp, TimeofDayManager.h, and TimeofDayManager.cpp. Or just download the source package DayNightSource.7z to avoid downloading all of them separately.
- Copy over the contents (make sure to edit to be your class names etc) of the above files to your files.
- Now go into your editor and make a BP of TimeofDayManager (BP_TimeofDayManager) and drop that into your level.
- Open up the BP_TimeofDayManager and on Tick do the following.
If you're too lazy to do all of this yourself then just download the project (daynight.7z).
until next time